Skip to content

PdfDocumentView Class

Definition

Namespace: Xfinium.Pdf.View

Defines a viewer control for PDF files.

C#
public class PdfDocumentView : Control, IComponent, IDisposable, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject, IOleWindow, IViewObject, IViewObject2, IPersist, IPersistStreamInit, IPersistPropertyBag, IPersistStorage, IQuickActivate, ISupportOleDropSource, IDropTarget, ISynchronizeInvoke, IWin32Window, IArrangedElement, IBindableComponent, IKeyboardToolTip, IHandle, IPdfView

Inheritance: Object → MarshalByRefObject → Component → Control → PdfDocumentView

Implements: IComponent, IDisposable, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject, IOleWindow, IViewObject, IViewObject2, IPersist, IPersistStreamInit, IPersistPropertyBag, IPersistStorage, IQuickActivate, ISupportOleDropSource, IDropTarget, ISynchronizeInvoke, IWin32Window, IArrangedElement, IBindableComponent, IKeyboardToolTip, IHandle, IPdfView

Remarks

Use this control to display PDF files. Set the Document property to display the desired PDF document. Set the Zoom property to adjust the zoom level. Use the PageDisplayLayout property to specify how the pages are arranged in the viewer. The UserInteractionMode property can be used to specify how the user interacts with the PDF document displayed in the viewer.

PdfDocumentView control

The control can display PDF files loaded from a file or from a stream. The document can be loaded entirely in memory

C#
// sample.pdf is loaded entirely in memory, it can be deleted from disk after this call.
documentView.Document.Load(new PdfFixedDocument("sample.pdf"));
or can be loaded on demand from a file or stream
C#
1
2
3
// sample.pdf is loaded on demand, it cannot be deleted from disk after this call,
// the file must be available as long as it is displayed in the viewer.
documentView.Document.Load("sample.pdf");

Page display layouts

The PDF pages in the viewer can be arranged in different layouts, column oriented, row oriented or fixed grid, the PageDisplayLayout property being responsible for specifying the layout.
The column oriented layout is specified by the PdfColumnBasedPageDisplayLayout class.

C#
// The PDF pages are displayed on 3 columns.
documentView.PageDisplayLayout = new PdfColumnBasedPageDisplayLayout(3);

The row oriented layout is specified by the PdfRowBasedPageDisplayLayout class.

C#
// The PDF pages are displayed on a single row.
documentView.PageDisplayLayout = new PdfRowBasedPageDisplayLayout(1);

To display the document in single page mode the fixed grid layout is used, specified by the PdfFixedGridPageDisplayLayout class.

C#
// The control displays a single PDF page by specifying a grid of 1 row and 1 column.
documentView.PageDisplayLayout = new PdfFixedGridPageDisplayLayout(1, 1);

Page zooming

The PDF pages can be zoomed in and out using the Zoom property. The zoom level can be specified as a percentage of the original page size (100% zoom is the original size), or by using the PdfZoomMode enumeration to specify a zoom mode. The pages can also be zoomed in and out using the CTRL key + mouse wheel or on touch devices by pinching the screen.

User interaction

The UserInteractionMode property can be used to specify how the user interacts with the PDF document displayed in the viewer. The user can select text or rectangular page areas (PdfUserInteractionMode.SelectContent mode), can add annotations to the document (any of the PdfUserInteractionMode.Add-Annotation modes), can add form fields to the document (any of the PdfUserInteractionMode.Add-Field modes) or can highlight/underline text in the document (PdfUserInteractionMode.HighlightText and PdfUserInteractionMode.FlatUnderlineText modes).

Context menus

The viewer control can display a default context menu depending on where the user right clicks on the document.

Page context menu

When the user right clicks on a PDF page, the default context menu is displayed, allowing the user to rotate the page or delete it. The following options are available in the default page context menu:

The default context menu can be disabled by setting the ShowDefaultPageContextMenu property to false.

Example

In your form's constructor connect the document view to a PdfVisualDocument:

C#
public AppForm()
{
    InitializeComponent();

    // ...

    document = new PdfVisualDocument();
    documentView.Document = document;

    // ...
}
When the form is closed, the viewer control need to be disposed explicitly as follows:
C#
1
2
3
4
5
6
7
8
protected override void OnFormClosing(FormClosingEventArgs e)
{
    base.OnFormClosing(e);

    document.Close();
    documentView.Dispose();
    document.Dispose();
}

Constructor

Name Description
PdfDocumentView() Initializes a new PdfDocumentView object.

Properties

Name Description
AnnotationSelectionRectangleAppearance Gets or sets the appearance of the annotation selection rectangle.
AnnotationToolTips Gets or sets the annotation tooltips.
ContentPosition Gets the content position.
ContentSize Gets the content size.
DefaultCircleAnnotationAppearance Gets or sets the default appearance of the circle annotation.
DefaultCloudSquareAnnotationAppearance Gets or sets the default appearance of the cloud square annotation.
DefaultFileAttachmentAnnotationAppearance Gets or sets the default appearance of the file attachment annotation.
DefaultFormFieldAppearance Gets or sets the default appearance of the form fields.
DefaultFreeTextAnnotationAppearance Gets or sets the default appearance of the free text annotation.
DefaultHighlightAnnotationAppearance Gets or sets the default appearance of the highlight annotation.
DefaultInkAnnotationAppearance Gets or sets the default appearance of the ink annotation.
DefaultLineAnnotationAppearance Gets or sets the default appearance of the line annotation.
DefaultLinkAnnotationAppearance Gets or sets the default appearance of the link annotation.
DefaultPolylineAnnotationAppearance Gets or sets the default appearance of the polyline annotation.
DefaultRubberStampAnnotationAppearance Gets or sets the default appearance of the rubber stamp annotation.
DefaultSquareAnnotationAppearance Gets or sets the default appearance of the square annotation.
DefaultSquigglyAnnotationAppearance Gets or sets the default appearance of the squiggly annotation.
DefaultStrikeoutAnnotationAppearance Gets or sets the default appearance of the strikeout annotation.
DefaultTextAnnotationAppearance Gets or sets the default appearance of the text annotation.
DefaultUnderlineAnnotationAppearance Gets or sets the default appearance of the underline annotation.
Document Gets or sets the document displayed in the viewer.
FormDesigner Gets the active form designer.
GraphicRendererFactory Gets or sets the graphic renderer factory.
PageDisplayLayout Gets or sets the current page display layout.
PageNumber Gets or sets the page number.
ResizeHandleStyle Gets or sets the style of the resize handles.
RestrictAnnotationsToVisiblePageArea Gets or sets a flag indicating whether annotations can be added or moved only in the visible page area.
SelectionRectangleAppearance Gets or sets the appearance of the selection rectangle.
ShowAnnotations Gets or sets a value indicating whether the annotations should be displayed or not.
ShowDefaultAnnotationContextMenu Gets of sets a flag indicating whether the default annotations context menu should be displayed when right-clicking on an annotation.
ShowDefaultPageContextMenu Gets of sets a flag indicating whether the default page context menu should be displayed when right-clicking on a page.
ShowFormFields Gets or sets a value indicating whether the form fields should be displayed or not.
ShowPageNumberIndicator Shows or hides the page number indicator in the bottom left corner of the PdfDocumentView control.
TextSearchResultColor Gets or sets the color used for highlighting the text search results.
TextSelectionAppearance Gets or sets the appearance of the text selection.
UserInteractionMode Gets or sets the user interaction mode.
Zoom Gets or sets the zoom level.
ZoomMode Gets or sets the current zoom mode.

Methods

Name Description
ConvertPagePointToViewerPoint Converts a page point in page visual coordinates to a viewer point in viewer coordinates.
GetSelectedAnnotations Gets the collection of selected annotations in the control.
GetVisiblePages Gets the list of visible pages.
ScrollToPageLocation Scrolls the viewer to the specified page at the given location.

Events

Name Description
ContentPainted Gets or sets the event that is fired after the viewer content has been drawn.
ContentPositionChanged Gets or sets the event that is fired when the content position has changed.
ContentSizeChanged Gets or sets the event that is fired when the size of displayed content changes.
ZoomChanged Gets or sets the event that is fired when the zoom has changed.
ZoomModeChanged Gets or sets the event that is fired when the ZoomMode has changed.
UserInteractionModeChanged Gets or sets the event that is fired when the UserInteractionMode has changed.
PageNumberChanged Gets or sets the event that is fired when the page number has changed.
PageClick Gets or sets the event that is fired when a page has been clicked.
PageDoubleClick Gets or sets the event that is fired when a page has been double clicked.
PageContextMenu Gets or sets the event that is fired when a page context menu should be displayed.
BeforePageDelete Occurs before a page is deleted using the Delete menu item in page's default context menu.
AfterPageDelete Occurs after a page has been deleted.
PageRenderingStarted Gets or sets the event that is fired when a page begins to be displayed.
PageRenderingCompleted Gets or sets the event that is fired when the page content for the page visible area is displayed in full.
PageRenderingCancelled Gets or sets the event that is fired when the page stops displaying content.
AnnotationClick Gets or sets the event that is fired when an annotation has been clicked.
AnnotationDoubleClick Gets or sets the event that is fired when an annotation has been double clicked.
AnnotationContextMenu Gets or sets the event that is fired when an annotation context menu should be displayed.
BeforeLinkExecute Gets or sets the event that is fired before a link is executed.
AfterLinkExecute Gets or sets the event that is fired after a link has been executed.
AnnotationSelected Gets or sets the event that is fired when an annotation is selected the PdfDocumentView control.
AnnotationDeselected Gets or sets the event that is fired when an annotation is deselected the PdfDocumentView control.
BeforeAnnotationAdd Gets or sets the event that is fired before an annotation is added through the PdfDocumentView control.
AfterAnnotationAdd Gets or sets the event that is fired after an annotation has been added through the PdfDocumentView control.
BeforeAnnotationMove Gets or sets the event that is fired when an annotation is about to be moved.
AfterAnnotationMove Gets or sets the event that is fired after an annotation has been moved.
BeforeAnnotationResize Gets or sets the event that is fired when an annotation is about to be resized.
AfterAnnotationResize Gets or sets the event that is fired after an annotation has been resized.
BeforeAnnotationDelete Occurs before an annotation is deleted using the DEL key or the Delete menu item in annotation's default context menu.
AfterAnnotationDelete Occurs after an annotation has been deleted.
AnnotationToolTipContentRequested Gets or sets the event that is fired when content is needed for annotation tooltip.
AnnotationToolTipPopup Gets or sets the event that is fired before an annotation tooltip is displayed.
AfterContentSelect Gets or sets the event that is fired after content has been selected on the page.
SelectedContentContextMenu Gets or sets the event that is fired when a context menu should be displayed for selected content.
BeforeFieldAdd Gets or sets the event that is fired before a form field is added through the PdfDocumentView control.
AfterFieldAdd Gets or sets the event that is fired after a form field has been added through the PdfDocumentView control.