Search code examples
c#.netvb.netprintingprintdocument

Issues Resizing Image to fit on a printed page


I am trying to print an image (from file) to a the printer using a PrintDocument.

I am re-sizing my image so that it is scaled to be full page on the printout when I print this the image is cropped slightly.

EDIT 2

I am using the margins to calculate the area to use:

With printSettings.DefaultPageSettings
    Dim areaWidth As Single = .Bounds.Width - .Margins.Left - .Margins.Right
    Dim areaHeight As Single = .Bounds.Height - .Margins.Top - .Margins.Bottom
End With

The bounds of the page are 1169x827 (A4) and with the margins it is 1137x795.

After resize my image size is 1092x682 and I am using the following code to draw it: e.Graphics.DrawImage(printBitmap, .Margins.Left, .Margins.Top)

The annoying thing is that when I print to the PrintPreviewDialog it is scaled perfectly but when I print the exact same code to the actual printer it does not fit.

EDIT 3

Full code can be found at this url Usage:

Dim clsPrint As New clsPrinting
    With clsPrint
        .Landscape = True
        .SetMinimumMargins()
        If .ShowPrintDialog Then
            .Documentname = "Some doc name"
            .Preview = False 'When True shows ok
            .PrintImage("filename of a png file")
        End If
    End With

Solution

  • I did not find a solution to this problem. I worked around it by using the printer margins when performing a print preview and ignoring the margins (start at 0,0 origin) when actually printing. I believe that this is possibly a bug in the printer driver? But I can't confirm.