Adjust the Document View
- 4 minutes to read
The topic consists of the following sections:
- Change the Page Display
- Browse Document Pages
- Rotate a Document
- Zoom a Document
- Previous and Next View
Change the Page Display
Specify the PdfViewerControl.PageLayout property to define how the PDF Viewer displays document pages. The DevExpress.Pdf.PdfPageLayout enumeration values specify the page layout mode as follows:
PdfPageLayout value | Page Display Mode |
---|---|
PdfPageLayout.OneColumn | Single Page View with enabled scrolling |
PdfPageLayout.SinglePage | Single Page View |
PdfPageLayout.TwoColumnLeft | Two Page View with enabled scrolling |
PdfPageLayout.TwoColumnRight | Two Page View with enabled scrolling + shows the cover page |
PdfPageLayout.TwoPageLeft | Two Page View |
PdfPageLayout.TwoPageRight | Two Page View + shows the cover page |
The code sample below specifies the PdfViewerControl.PageLayout property so that the PDF Viewer shows two pages at a time with enabled scrolling:
<dxpdf:PdfViewerControl x:Name="pdfViewer"
PageLayout="TwoColumnLeft"/>
The PdfViewerControl.PageLayoutChanged event occurs after the PageLayout property value has been changed.
Page Display in the User Interface
End users can select the desired page display mode from the Page Display drop-down list.
Browse Document Pages
Use the DocumentViewerControl.CurrentPageNumber property in the PdfViewerControl.DocumentLoaded handler to specify the displayed page. Otherwise, the property value is reset to 1. The DocumentViewerControl.PageCount property returns the total number of document pages.
private void PdfViewer_DocumentLoaded(object sender, RoutedEventArgs e)
{
pdfViewer.CurrentPageNumber = 5;
}
Page Navigation in the User Interface
PDF Viewer provides the following ways to browse document pages.
Previous and Next buttons;
The Pager used to show the current page number and the total number of pages. Type a required page number and press ENTER to go to this page.
The Page Thumbnails panel located on the Navigation pane. Click a page thumbnail to go to the required page.
Rotate a Document
Use the DocumentViewerControl.PageRotation property to specify document pages’ rotation angle.
private void PdfViewer_DocumentLoaded(object sender, RoutedEventArgs e)
{
pdfViewer.PageRotation = Rotation.Rotate270;
}
The DocumentViewerControl.PageRotationChanged event occurs when the page rotation changes.
Rotate a Document: Built-in UI Commands
Users can use Rotate Clockwise item from the context menu to rotate document pages. You can also use the Ctrl + Shift + Add shortcut.
Note
The PDF Viewer does not provide and API or User Interface features to rotate individual pages. Use the PDF Document API instead.
The PDF Document API is a part of the Office File API or Universal subscription only, and is not included in the WPF subscription. Please refer to the DevExpress Subscription page for pricing information.
Zoom a Document
The DocumentViewerControl.ZoomMode property allows you to zoom in and out of a document. When the property is set to ZoomMode.Custom, the DocumentViewerControl.ZoomFactor property defines the document zoom factor value. The property’s minimum value is 0.1 (10%), the maximum value is 5 (500%).
The code sample below sets the zoom factor to 75% for a loaded document.
private void PdfViewer_DocumentLoaded(object sender, RoutedEventArgs e)
{
pdfViewer.ZoomMode = DevExpress.Xpf.DocumentViewer.ZoomMode.Custom;
pdfViewer.ZoomFactor = 0.75;
}
You can also specify this property in XAML
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing">
...
<dxp:DocumentPreviewControl ZoomFactor="0.75"/>
</Window>
Handle the DocumentViewerControl.ZoomChanged event to perform specific actions after a document’s zoom is changed.
Zoom a Document: Built-in UI Commands
Use buttons on the Zoom ribbon group on the PDF Viewer tab to zoom a document.
You can press Ctrl+Plus and Ctrl+Minus, or hold Ctrl and rotate the mouse wheel to zoom a page.
Use Marquee Zoom Tool
The Marquee zoom tool allows users to zoom in a particular part of the page.
Right-click the document and select the Marquee Zoom item in the context menu to activate the tool.
Set PdfViewerControl.CursorMode property to CursorModeType.MarqueeZoom to activate the marquee zoom in code.
Drag a rectangle around the page area to zoom in on it. Click the area to increase the zoom level. Click while pressing the Ctrl key to decrease the zoom level.
Previous and Next View
Execute the PdfPreviousViewCommand or NextViewCommand command to switch between recently used page display styles (that is, previous zoom factor, rotation angle, and page display mode). If the page display options were not changed, the PDF Viewer shows the previously displayed page.
Previous and Next View in the User Interface
The Previous view and Next view items to navigate between recently used page display styles.
You can also use Alt+Left or Alt+Right shortcuts to go to previous views and pages. Note that the PDF Viewer shows these pages in reverse order.