【问题标题】:How can I flip/rotate a PrintDocument in .NET?如何在 .NET 中翻转/旋转 PrintDocument?
【发布时间】:2009-01-09 20:47:28
【问题描述】:

我有一个文档,我想在打印时翻转/旋转 180 度。 (这是由于打印机中标签纸的方向所致)。

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

我认为这个属性受打印机驱动程序的影响,因此不是“可设置的”。

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

【问题讨论】:

    标签: .net vb.net orientation printdocument


    【解决方案1】:

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

    PrintDocument 类有一个 Graphics 对象可供您使用,该对象又具有一个 TranslateTransformRotateTransform 方法,可让您在需要的地方获取内容。

    在您操作图形对象之前,通常需要对其进行复制,这样您可以在完成后再次恢复它。

    【讨论】:

    • 未经测试,但听起来很有希望!
    • 已在我上一个雇主的一些 PDF 争论代码中成功使用它。唉,因为我离开了,我无法访问实际的代码,但它很容易实现。
    【解决方案2】:

    【讨论】:

    • 但我希望它与 Landscape 成 180 度。
    • 你不能把标签纸转过来吗?
    • 或者它是绕线而不是放在托盘中?
    【解决方案3】:

    在 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
    

    【讨论】:

      【解决方案4】:

      在将其分配给打印机之前,您是否尝试过 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;                      
      
                      }
      

      【讨论】:

        猜你喜欢
        • 2013-04-20
        • 2019-04-03
        • 2013-01-04
        • 1970-01-01
        • 2022-09-27
        • 2017-02-16
        • 1970-01-01
        • 2022-11-14
        • 2011-06-25
        相关资源
        最近更新 更多