How to find the actual printable area? (PrintDocument)

前端 未结 3 2056
忘了有多久
忘了有多久 2020-11-28 20:24

Why is finding out this magic Rectangle so difficult?

In the OnPrintPage event I have PrintPageEventArgs and I am trying to draw using the Graphics within the bounds

3条回答
  •  野性不改
    2020-11-28 21:07

    I think what you need is simply redraw the image to fit whatever the paper size being used. Here's my code:

    Protected Overrides Sub OnPrintPage(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
            Dim img As Image = Nothing 'Your image source
    
            Dim ps As PaperSize = MyBase.PrinterSettings.DefaultPageSettings.PaperSize
            Dim pF As RectangleF = MyBase.PrinterSettings.DefaultPageSettings.PrintableArea
            Dim srcF As New RectangleF(0, 0, pg.ImageSize.Width, pg.ImageSize.Height)
            Dim dstF As New RectangleF(0, 0, pF.Width, pF.Height)
    
            e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
            e.Graphics.DrawImage(img, dstF, srcF, GraphicsUnit.Pixel)
    
            MyBase.OnPrintPage(e)
    End Sub
    

提交回复
热议问题