windowsforms-devexpress-dot-xtrapdfviewer-dot-pdfviewer-3fd5302c.md
Occurs before the PdfViewer.PrintPage event.
Namespace : DevExpress.XtraPdfViewer
Assembly : DevExpress.XtraPdfViewer.v25.2.dll
NuGet Package : DevExpress.Win.PdfViewer
public event PdfQueryPageSettingsEventHandler QueryPageSettings
Public Event QueryPageSettings As PdfQueryPageSettingsEventHandler
The QueryPageSettings event's data class is PdfQueryPageSettingsEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Cancel | Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs. |
| PageNumber | Gets the page number in a document. |
| PageSettings | Gets or sets the page settings for the page to be printed. Inherited from QueryPageSettingsEventArgs. |
| PageSize | Gets the size of the current page. |
| PrintAction | Returns PrintToFile in all cases. Inherited from PrintEventArgs. |
| PrintInGrayscale | Gets or sets a value which indicates whether to print the document content in grayscale. |
Handle the QueryPageSettings event to specify print settings for a specific page.
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