Back to Devexpress

PdfViewerControl.QueryPageSettings Event

wpf-devexpress-dot-xpf-dot-pdfviewer-dot-pdfviewercontrol-0e4dc26b.md

latest7.0 KB
Original Source

PdfViewerControl.QueryPageSettings Event

Occurs immediately before the PdfViewerControl.PrintPage event.

Namespace : DevExpress.Xpf.PdfViewer

Assembly : DevExpress.Xpf.PdfViewer.v25.2.dll

NuGet Package : DevExpress.Wpf.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
CancelSpecifies a value indicating whether the event should be canceled.
HandledGets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
PageNumberGets the page number in a document.
PageSettingsSpecifies the page settings for the page to be printed.
PageSizeGets the size of the current page.
PrintActionGets a value indicating what type of print operation is occurring.
PrintInGrayscaleGets or sets a value which indicates whether to print the document content in grayscale.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.

The event data class exposes the following methods:

MethodDescription
InvokeEventHandler(Delegate, Object)When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object)When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

You can print each page of a document using different page settings. To access the page settings, use the PdfQueryPageSettingsEventArgs.PageSettings property.

To obtain the page number and page size for each printed page, use 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.

csharp
using DevExpress.Xpf.PdfViewer;
using System.Drawing;
//...

private void pdfViewer_QueryPageSettings(DependencyObject d, PdfQueryPageSettingsEventArgs e)
{
    // Print the second page in landscape size.
    if (e.PageNumber == 2)
    {
        e.PageSettings.Landscape = true;
    }
    else e.PageSettings.Landscape = false;
}

private void pdfViewer_PrintPage(DependencyObject d, 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.Xpf.PdfViewer
Imports System.Drawing
'...

Private Sub pdfViewer_QueryPageSettings(ByVal d As DependencyObject, 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

Private Sub pdfViewer_PrintPage(ByVal d As DependencyObject, 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

PdfViewerControl Class

PdfViewerControl Members

DevExpress.Xpf.PdfViewer Namespace