Back to Devexpress

PdfDocumentProcessor.QueryPageSettings Event

officefileapi-devexpress-dot-pdf-dot-pdfdocumentprocessor-31946fc3.md

latest8.7 KB
Original Source

PdfDocumentProcessor.QueryPageSettings Event

Occurs before the PdfDocumentProcessor.PrintPage event.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

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

You can print each page of a document using different page settings. To access the page settings, use the corresponding property of the QueryPageSettingsEventArgs. For more information about other properties of QueryPageSettingsEventArgs , see the QueryPageSettingsEventArgs Class MSDN topic.

You can also obtain the page number and page size for each page in a document using the PdfQueryPageSettingsEventArgs.PageNumber and PdfQueryPageSettingsEventArgs.PageSize properties, correspondingly.

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.

View Example: PDF Document API - Customize PDF Print Output

csharp
using DevExpress.Pdf;
using System.Drawing;

// Create a PDF Document Processor instance and load a PDF file
using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) {
    documentProcessor.LoadDocument(@"..\..\Demo.pdf");

    // Declare PDF printer settings.
    PdfPrinterSettings settings = new PdfPrinterSettings();

    // Specify the page numbers to be printed.
    settings.PageNumbers = new int[] { 1, 2, 3, 4, 5, 6 };

    // Handle the PrintPage event to specify print output.
    documentProcessor.PrintPage += OnPrintPage;

    // Handle the QueryPageSettings event to customize settings for a page to be printed.
    documentProcessor.QueryPageSettings += OnQueryPageSettings;

    // Print the document using the specified printer settings.
    documentProcessor.Print(settings);

    // Unsubscribe from PrintPage and QueryPageSettings events. 
    documentProcessor.PrintPage -= OnPrintPage;
    documentProcessor.QueryPageSettings -= OnQueryPageSettings;
}

private static void OnQueryPageSettings(object sender, PdfQueryPageSettingsEventArgs e) {

    // Print the second page in landscape size.
    if (e.PageNumber == 2) {
        e.PageSettings.Landscape = true;
    }
    else e.PageSettings.Landscape = false;
}

// Specify what happens when the PrintPage event is raised.
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
Imports DevExpress.Pdf
Imports System.Drawing

' Create a PDF Document Processor instance and load a PDF file
Using documentProcessor As New PdfDocumentProcessor()
    documentProcessor.LoadDocument("..\..\Demo.pdf")

    ' Declare the PDF printer settings
    Dim settings As New PdfPrinterSettings()

    ' Specify the page numbers to be printed
    settings.PageNumbers = New Integer() { 1, 2, 3, 4, 5, 6 }

    ' Handle the PrintPage event to specify print output
    AddHandler documentProcessor.PrintPage, AddressOf OnPrintPage

    ' Handle the QueryPageSettings event to customize settings for a page to be printed
    AddHandler documentProcessor.QueryPageSettings, AddressOf OnQueryPageSettings

    ' Print the document using the specified printer settings.
    documentProcessor.Print(settings)

    ' Unsubscribe from PrintPage and QueryPageSettings events. 
    RemoveHandler documentProcessor.PrintPage, AddressOf OnPrintPage
    RemoveHandler documentProcessor.QueryPageSettings, AddressOf OnQueryPageSettings
End Using
End Sub

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the QueryPageSettings event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-customize-pdf-print-output/CS/CustomizePrintSettings/Program.cs#L22

csharp
// Handle the QueryPageSettings event to customize settings for a page to be printed.
documentProcessor.QueryPageSettings += OnQueryPageSettings;

pdf-document-api-customize-pdf-print-output/VB/CustomizePrintSettings/Program.vb#L19

vb
' Handle the QueryPageSettings event to customize settings for a page to be printed.
AddHandler documentProcessor.QueryPageSettings, AddressOf OnQueryPageSettings
' Print the document using the specified printer settings.

See Also

PdfDocumentProcessor Class

PdfDocumentProcessor Members

DevExpress.Pdf Namespace