Q: When I am printing a PDF, its cutting the right side and bottom of
the PDF off slightly , I looked at the sample code and ran it using
same pdf and it does the same thing printing the bitmap or using the
PDFDraw class. Any Assistance would greatly be appreciated.
Here is my code:
Private Sub Print_Document()
Try
'create PDF Rasterizer object
PDFDraw = New PDFDraw
itr = PDFDocument.PageBegin()
Printer = New PrintDocument
Printer.Print()
PDFDraw = Nothing
Printer = Nothing
Catch ex As Exception
LogError(ex, True)
End Try
End Sub
Private Sub PrintPage(ByVal sender As System.Object, ByVal ev As
PrintPageEventArgs) Handles Printer.PrintPage
Dim rectPage As Rectangle = ev.PageBounds
Dim gr As System.Drawing.Graphics = ev.Graphics
Dim dpi As Single = gr.DpiX
If dpi > 200 Then
dpi = 200
End If
PDFDraw.SetDPI(dpi)
Dim bmp As Bitmap = PDFDraw.GetBitmap(itr.Current())
gr.DrawImage(bmp, rectPage, 0, 0, bmp.Width, bmp.Height,
GraphicsUnit.Pixel)
itr.Next()
If itr.Equals(PDFDocument.PageEnd()) Then
ev.HasMorePages = False
Else
ev.HasMorePages = True
End If
End Sub
-----
A:
You may want to adjust page boundary (i.e. rectPage ) to account for
the HardMarginX.
Dim rectPage As Rectangle = ev.PageBounds
Dim left As Double = (rectPage.Left - ev.PageSettings.HardMarginX)
Dim right As Double = (rectPage.Right - ev.PageSettings.HardMarginX)
Dim top As Double = (rectPage.Top - ev.PageSettings.HardMarginY)
Dim bottom As Double = (rectPage.Bottom - ev.PageSettings.HardMarginY)
rectPage.Left = left
rectPage.Right = right
rectPage.Top = top
rectPage.Bottom = bottom
...
Another printing example is as follows:
Dim rectPage As Rectangle = ev.PageBounds 'print without margins
Dim gr As System.Drawing.Graphics = ev.Graphics
gr.PageUnit = GraphicsUnit.Inch
Dim dpi As Double = gr.DpiX
If dpi > 200 Then dpi = 200
Dim left As Double = (rectPage.Left - ev.PageSettings.HardMarginX) /
100.0
Dim right As Double = (rectPage.Right - ev.PageSettings.HardMarginX) /
100.0
Dim top As Double = (rectPage.Top - ev.PageSettings.HardMarginY) /
100.0
Dim bottom As Double = (rectPage.Bottom - ev.PageSettings.HardMarginY)
/ 100.0
Dim rect As PDFTRON.PDF.Rect = New Rect(left * 72, bottom * 72, right *
72, top * 72)
Try
pdfDraw.SetImageSmoothing(True)
pdfDraw.SetAntiAliasing(True)
' pdfDraw.SetRasterizerType(PDFTRON.PDF.PDFRasterizer.Type.e_GDIPlus)
pdfDraw.SetDPI(dpi)
pdfDraw.DrawInRect(printItr(PnlActive).Current, gr, rect)
Catch ex As Exception
MessageBox.Show("Printing Error: " + ex.ToString)
End Try