Back to Devexpress

PdfViewer.QueryPageSettings Event

windowsforms-devexpress-dot-xtrapdfviewer-dot-pdfviewer-3fd5302c.md

latest4.6 KB
Original Source

PdfViewer.QueryPageSettings Event

Occurs before the PdfViewer.PrintPage event.

Namespace : DevExpress.XtraPdfViewer

Assembly : DevExpress.XtraPdfViewer.v25.2.dll

NuGet Package : DevExpress.Win.PdfViewer

Declaration

csharp
public event PdfQueryPageSettingsEventHandler QueryPageSettings
vb
Public Event QueryPageSettings As PdfQueryPageSettingsEventHandler

Event Data

The QueryPageSettings event's data class is PdfQueryPageSettingsEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
PageNumberGets the page number in a document.
PageSettingsGets or sets the page settings for the page to be printed. Inherited from QueryPageSettingsEventArgs.
PageSizeGets the size of the current page.
PrintActionReturns PrintToFile in all cases. Inherited from PrintEventArgs.
PrintInGrayscaleGets or sets a value which indicates whether to print the document content in grayscale.

Remarks

Handle the QueryPageSettings event to specify print settings for a specific page.

Example

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.

csharp
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));
}
vb
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

PdfViewer Class

PdfViewer Members

DevExpress.XtraPdfViewer Namespace