如何在.NET中翻转/旋转PrintDocument?

时间:2009-01-09 20:47:28

标签: .net vb.net orientation printdocument

我有一份文件,我希望在打印时翻转/旋转180度。 (这是由于打印机中标签纸的方向)。

有一个属性PrintDocument.PrinterSettings.LandscapeAngle,但它是只读的。

我认为此属性受打印机驱动程序的影响,因此无法“设置”。

有没有一种很好的方法可以将打印件旋转180度而不必做任何太讨厌的事情?

4 个答案:

答案 0 :(得分:2)

答案 1 :(得分:2)

我想这取决于你所定义的“任何太令人讨厌的东西”: - )

PrintDocument类有一个Graphics对象,您可以使用该对象,然后使用TranslateTransformRotateTransform方法让您获取需要它们。

在操作之前,通常需要获取图形对象的副本,以便在完成后再将其恢复。

答案 2 :(得分:2)

打印表单并在VB.NET中翻转/旋转PrintDocument并将DefaultPageSettings设置为横向

Dim WithEvents mPrintDocument As New PrintDocument
Dim mPrintBitMap As Bitmap
Private Sub m_PrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mPrintDocument.PrintPage
    mPrintBitMap.RotateFlip(RotateFlipType.Rotate90FlipNone)
    mPrintDocument.PrinterSettings.DefaultPageSettings.Landscape = True
    ' Draw the image centered.     
    Dim lWidth As Integer = e.MarginBounds.X + (e.MarginBounds.Width - mPrintBitMap.Width) \ 2
    Dim lHeight As Integer = e.MarginBounds.Y + (e.MarginBounds.Height - mPrintBitMap.Height) \ 2

    e.Graphics.DrawImage(mPrintBitMap, lWidth, lHeight)
    ' There's only one page.   
    e.HasMorePages = False
End Sub
Private Sub B_print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_print.Click
    ' Copy the form image into a bitmap.    
    mPrintBitMap = New Bitmap(Me.Width, Me.Height)
    Dim lRect As System.Drawing.Rectangle
    lRect.Width = Me.Width
    lRect.Height = Me.Height
    Me.DrawToBitmap(mPrintBitMap, lRect)
    ' Make a PrintDocument and print.    
    mPrintDocument = New PrintDocument

    mPrintDocument.Print()

End Sub

答案 3 :(得分:1)

你有没有尝试过将它分配给打印机GDI自动旋转图像?多数民众赞成我所做的:

                _currentPage = Image.FromStream((MemoryStream)_queue.Dequeue());
                pageHeight = _currentPage.Height;
                pageWidth = _currentPage.Width;

                if (pageHeight < pageWidth)
                {
                    _currentPage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    pageHeight = _currentPage.Height;
                    pageWidth = _currentPage.Width;                      

                }