windowsforms-devexpress-dot-xtrapdfviewer-dot-pdfviewer-d0b6435c.md
Occurs when the document page is printed.
Namespace : DevExpress.XtraPdfViewer
Assembly : DevExpress.XtraPdfViewer.v25.2.dll
NuGet Package : DevExpress.Win.PdfViewer
public event PdfPrintPageEventHandler PrintPage
Public Event PrintPage As PdfPrintPageEventHandler
The PrintPage event's data class is PdfPrintPageEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Cancel | Gets or sets a value indicating whether the print job should be canceled. Inherited from PrintPageEventArgs. |
| Graphics | Gets the Graphics used to paint the page. Inherited from PrintPageEventArgs. |
| HasMorePages | Gets or sets a value indicating whether an additional page should be printed. Inherited from PrintPageEventArgs. |
| MarginBounds | Gets the rectangular area that represents the portion of the page inside the margins. Inherited from PrintPageEventArgs. |
| PageBounds | Gets the rectangular area that represents the total area of the page. Inherited from PrintPageEventArgs. |
| PageCount | Returns the total number of pages which were sent to the printer. |
| PageNumber | Returns the page number of the currently printed page. |
| PageSettings | Gets the page settings for the current page. Inherited from PrintPageEventArgs. |
Use this event to perform actions when the document is sent to a printer. Use the PageNumber and PageCount properties to retrive the current page number and the total number of pages.
Set the e.Cancel property to true to cancel the print job. See the following topic for more information: PrintPageEventArgs Class.
The code snippet below handles the QueryPageSettings and PrintPage events to specify the landscape orientation for a second page and add an image on each printed page.
pdfViewer.QueryPageSettings += PdfViewer_QueryPageSettings;
pdfViewer.PrintPage += OnPrintPage;
//...
private void PdfViewer_QueryPageSettings(object sender, PdfQueryPageSettingsEventArgs e)
{
// Print the second page in landscape size.
if (e.PageNumber == 2)
{
e.PageSettings.Landscape = true;
}
else e.PageSettings.Landscape = false;
}
private static void OnPrintPage(object sender, PdfPrintPageEventArgs e) {
// Draw a picture on each printed page.
using (Bitmap image = new Bitmap(@"..\..\DevExpress.png"))
e.Graphics.DrawImage(image, new RectangleF(10, 30, image.Width / 2, image.Height / 2));
}
AddHandler pdfViewer.PrintPage, AddressOf OnPrintPage
AddHandler pdfViewer.QueryPageSettings, AddressOf OnQueryPageSettings
'...
Private Shared Sub OnQueryPageSettings(ByVal sender As Object, ByVal e As PdfQueryPageSettingsEventArgs)
' Print the second page in landscape size.
If e.PageNumber = 2 Then
e.PageSettings.Landscape = True
Else
e.PageSettings.Landscape = False
End If
End Sub
' Specify what happens when the PrintPage event is raised.
Private Shared Sub OnPrintPage(ByVal sender As Object, ByVal e As PdfPrintPageEventArgs)
' Draw a picture on each printed page.
Using image As New Bitmap("..\..\DevExpress.png")
e.Graphics.DrawImage(image, New RectangleF(10, 30, image.Width \ 2, image.Height \ 2))
End Using
End Sub
See Also