.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

PdfDocumentProcessor.QueryPageSettings Event

Occurs immediately before the PdfDocumentProcessor.PrintPage event.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Docs.v21.1.dll

Declaration

public event PdfQueryPageSettingsEventHandler QueryPageSettings

Event Data

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.

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

This example shows how to customize print output and change settings for a page to be printed.

A document is printed with the specified initial printer settings using the PdfDocumentProcessor.Print method. In this example, the page numbers that should be printed in a document are specified using the PdfPrinterSettings.PageNumbers property.

When a page is printed, page settings for this page are queried via the PdfDocumentProcessor.QueryPageSettings event.

In this example, the second page of a document is printed in landscape orientation by setting the PdfQueryPageSettingsEventArgs.PageSettings.Landscape property to true when the PdfDocumentProcessor.QueryPageSettings event is handled.

When the document is sent to a printer, the PdfDocumentProcessor.PrintPage event is raised.

To draw an additional image on a printed page, the Graphics property of the PdfPrintPageEventArgs is used when the PdfDocumentProcessor.PrintPage event is handled. This image is drawn on each page by calling the Graphics.DrawImage method.

using DevExpress.Pdf;
using System.Drawing;

namespace CustomizePrintSettings {
    class Program {
        static void Main(string[] args) {

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

                // Declare the 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));
        }
    }
}
See Also