Class PdfView

This XAML control displays a PDF.

Inheritance
System.Object
Windows.UI.Xaml.DependencyObject
Windows.UI.Xaml.UIElement
Windows.UI.Xaml.FrameworkElement
Windows.UI.Xaml.Controls.Control
PdfView
Implements
Windows.UI.Composition.IAnimationObject
Windows.UI.Composition.IVisualElement
Namespace: PSPDFKit.UI
Assembly: PSPDFKit.dll
Syntax
public sealed class PdfView : Control, IAnimationObject, IVisualElement

Constructors

PdfView()

Default constructor.

Declaration
public PdfView()

Properties

AutoSave

Automatically save the file when the PdfView is unloaded or a new file is loaded. Default is None. When turned on, AutoSave will only work if the PdfView is properly unloaded. The document is not periodically saved. In addition, if the application is terminated by Windows then the document will not be saved and any changes will be lost. Handling the suspension of the application must be done by the application developer. Read more about the UWP Application Lifecycle and handling application suspension and termination here: https://blogs.windows.com/windowsdeveloper/2016/04/28/the-lifecycle-of-a-uwp-app/ https://pspdfkit.com/guides/windows/current/features/suspend-unloading/

Declaration
public AutoSaveMode AutoSave { get; set; }
Property Value
Type Description
AutoSaveMode

Controller

The UI controller for the currently opened Document

Declaration
public Controller Controller { get; }
Property Value
Type Description
Controller

Css

Custom CSS for the PdfView

Declaration
public Uri Css { get; set; }
Property Value
Type Description
System.Uri

Document

The currently opened Document.

Declaration
public Document Document { get; }
Property Value
Type Description
Document

EnableInkEraserModeStroke

Enables the stroke mode when using the Ink Eraser. If set to True, all of the strokes of the ink annotation will be removed when they're touched, otherwise only the individual points of the ink annotation are removed when they're touched. It defaults to False.

Declaration
public bool EnableInkEraserModeStroke { get; set; }
Property Value
Type Description
System.Boolean

EnablePdfJavaScript

Enables PDF JavaScript support. Disabled by default and can only be set once per instantiation of the PdfView. PDF documents may contain JavaScript for interactivity. This enables things like form validation, formatting, or automatic calculation which are performed by a JavaScript scripts inside the PDF document. Disabling JavaScript improves the general performance of the framework when PDF JavaScript support is not needed.

Declaration
public bool EnablePdfJavaScript { get; set; }
Property Value
Type Description
System.Boolean

IgnoreDocumentPermissions

If set to true PDF document permissions are ignored.

Disabled by default and can only be set once per instantiation of the PdfView.

If set by code, must be done before a document is loaded into the PdfView.

Declaration
public bool IgnoreDocumentPermissions { get; set; }
Property Value
Type Description
System.Boolean

InkEpsilonMinimumRange

Minimum range between two points for an ink annotation, in pixels. If set to 0, the optimization is disabled. The default value is 10 and the value can only be set once per instance of the view before loading a document.

Declaration
public double InkEpsilonMinimumRange { get; set; }
Property Value
Type Description
System.Double

IsHistoryEnabled

Sets if annotation edit history should be saved. By default it is set to false.

Declaration
public bool IsHistoryEnabled { get; set; }
Property Value
Type Description
System.Boolean

License

The PSPDFKit license key.

Declaration
public string License { get; set; }
Property Value
Type Description
System.String

MaxDefaultZoomLevel

Allows you to configure the maximum zoom level. This has to be set before loading the document. The largest zoom level at a given time will be calculated based on the page proportions and this option. This is not necessarily a hard limit. For example, in order to satisfy the 'fit to width' and 'fit to page' zoom modes, the actual maximum zoom may be higher. The default value is 10.

Declaration
public int MaxDefaultZoomLevel { get; set; }
Property Value
Type Description
System.Int32

MessageBoxImage

MessageBox image.

Declaration
public BitmapImage MessageBoxImage { get; set; }
Property Value
Type Description
Windows.UI.Xaml.Media.Imaging.BitmapImage

MessageBoxText

MessageBox text.

Declaration
public string MessageBoxText { get; set; }
Property Value
Type Description
System.String

MessageBoxVisibility

Visibility of the MessageBox.

Declaration
public Visibility MessageBoxVisibility { get; set; }
Property Value
Type Description
Windows.UI.Xaml.Visibility

PdfFileSource

A Windows.Storage.StorageFile representing a document to open.

Declaration
public StorageFile PdfFileSource { get; set; }
Property Value
Type Description
Windows.Storage.StorageFile

PdfFileSourceProperty

The file source as a Windows.Storage.StorageFile.

Declaration
public static DependencyProperty PdfFileSourceProperty { get; }
Property Value
Type Description
Windows.UI.Xaml.DependencyProperty

PdfUriSource

A System.Uri representing a document to open.

Declaration
public Uri PdfUriSource { get; set; }
Property Value
Type Description
System.Uri

PdfUriSourceProperty

The file source as a System.Uri.

Declaration
public static DependencyProperty PdfUriSourceProperty { get; }
Property Value
Type Description
Windows.UI.Xaml.DependencyProperty

PreventTextCopy

When copying of text is disabled, it's still possible to select text but copying either using the shortcut or a context menu will have no effect. Changing this property has no effect after a document has loaded. Load the document again if you wish to update this property. This is distinct making the document read-only. ReadOnly.

Declaration
public bool PreventTextCopy { get; set; }
Property Value
Type Description
System.Boolean

ReadOnly

Make the document read only if set to true. This is distinct from preventing text copying. PreventTextCopy.

Declaration
public bool ReadOnly { get; set; }
Property Value
Type Description
System.Boolean

ResetViewStatePropertiesOnLoad

Determines how the ViewState is reset or not before loading a new document.

Declaration
public ResetViewStateMode ResetViewStatePropertiesOnLoad { get; set; }
Property Value
Type Description
ResetViewStateMode

ShowAnnotations

Show or hide annotations.

Declaration
public bool ShowAnnotations { get; set; }
Property Value
Type Description
System.Boolean

ShowSignatureValidationStatusMode

Whether to show the digital signature status. Changing this value has no effect until a new document is opened.

Declaration
public ShowSignatureValidationStatusMode ShowSignatureValidationStatusMode { get; set; }
Property Value
Type Description
ShowSignatureValidationStatusMode

ShowToolbar

Show or hide the UI Toolbar.

Declaration
public bool ShowToolbar { get; set; }
Property Value
Type Description
System.Boolean

SidebarPlacement

Declaration
public SidebarPlacement SidebarPlacement { get; set; }
Property Value
Type Description
SidebarPlacement

WebViewVisibility

Visibility of the WebView.

Declaration
public Visibility WebViewVisibility { get; set; }
Property Value
Type Description
Windows.UI.Xaml.Visibility

Methods

GetAnnotationToolbarItems(AnnotationType)

Gets the IAnnotationToolbarItems shown.

Declaration
public IList<IAnnotationToolbarItem> GetAnnotationToolbarItems(AnnotationType typeName)
Parameters
Type Name Description
AnnotationType typeName
Returns
Type Description
System.Collections.Generic.IList<IAnnotationToolbarItem>

Current list of annotation toolbar items for a given annotation type

GetToolbarItems()

Gets the IToolbarItems shown.

Declaration
public IList<IToolbarItem> GetToolbarItems()
Returns
Type Description
System.Collections.Generic.IList<IToolbarItem>

Current list of toolbar items

HighlightResultsAsync(IEnumerable<Result>)

Highlights the search results in the UI. Pass an empty list to highlight nothing.

Declaration
public IAsyncAction HighlightResultsAsync(IEnumerable<Result> results)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Result> results

The collection of results to highlight.

Returns
Type Description
Windows.Foundation.IAsyncAction

OnApplyTemplate()

Windows.UI.Xaml.FrameworkElement.Windows.UI.Xaml.IFrameworkElementOverrides.OnApplyTemplate()
Declaration
protected override async void OnApplyTemplate()
Overrides
Windows.UI.Xaml.FrameworkElement.Windows.UI.Xaml.IFrameworkElementOverrides.OnApplyTemplate()

OpenStorageFileAsync(StorageFile)

Asynchronously open a document represented by a Windows.Storage.StorageFile

Declaration
public IAsyncAction OpenStorageFileAsync(StorageFile file)
Parameters
Type Name Description
Windows.Storage.StorageFile file

The Windows.Storage.StorageFile representing the document.

Returns
Type Description
Windows.Foundation.IAsyncAction

OpenStorageFileWithPasswordAsync(StorageFile, String)

Asynchronously open a document represented by a Windows.Storage.StorageFile

Declaration
public IAsyncAction OpenStorageFileWithPasswordAsync(StorageFile file, string password)
Parameters
Type Name Description
Windows.Storage.StorageFile file

The Windows.Storage.StorageFile representing the document.

System.String password

The password required to open the document.

Returns
Type Description
Windows.Foundation.IAsyncAction

OpenUriAsync(Uri)

Asynchronously open a document represented by a System.Uri

Declaration
public IAsyncAction OpenUriAsync(Uri uri)
Parameters
Type Name Description
System.Uri uri

The System.Uri representing the document.

Returns
Type Description
Windows.Foundation.IAsyncAction

OpenUriAsync(Uri, String)

Asynchronously open a document represented by a System.Uri

Declaration
public IAsyncAction OpenUriAsync(Uri uri, string password)
Parameters
Type Name Description
System.Uri uri

The System.Uri representing the document.

System.String password

The password required to open the document.

Returns
Type Description
Windows.Foundation.IAsyncAction

ResetAsync()

Resets the WebView2 to it's initial state. This can be useful for unloading the document from memory without having to destroy the view. Resetting is not required if the view is going to be unloaded as usual. It is not necessary to reset a view before loading a new document. The method can be called any time after the view has been initialized InitializationCompletedHandler. The InitializationCompletedHandler will be fired again after resetting the view.

Declaration
public IAsyncAction ResetAsync()
Returns
Type Description
Windows.Foundation.IAsyncAction

SetAnnotationToolbarItemsAsync(AnnotationType, IList<IAnnotationToolbarItem>)

Sets the IAnnotationToolbarItems to be shown. This will overwrite any items currently held by the annotation toolbar. If the view is not initialized, the item will be cached and set when the view is ready.

Declaration
public IAsyncAction SetAnnotationToolbarItemsAsync(AnnotationType typeName, IList<IAnnotationToolbarItem> annotationToolbarItems)
Parameters
Type Name Description
AnnotationType typeName
System.Collections.Generic.IList<IAnnotationToolbarItem> annotationToolbarItems
Returns
Type Description
Windows.Foundation.IAsyncAction

SetToolbarItemsAsync(IList<IToolbarItem>)

Sets the IToolbarItems to be show. This will overwrite any items currently held by the toolbar. If the view is not initialized, the item will be cached and set when the view is ready.

Note: Default buttons are present in PSPDFKit.UI.ToolbarComponents namespace.

Declaration
public IAsyncAction SetToolbarItemsAsync(IList<IToolbarItem> toolbarItems)
Parameters
Type Name Description
System.Collections.Generic.IList<IToolbarItem> toolbarItems
Returns
Type Description
Windows.Foundation.IAsyncAction

ShowMessage(String)

Hides the currently displayed document, if any, and shows a message.

Declaration
public void ShowMessage(string message)
Parameters
Type Name Description
System.String message

The message to show.

Events

InitializationCompletedHandler

The event handler invoked once the PdfView has completed initialization.

Declaration
public event TypedEventHandler<PdfView, Document> InitializationCompletedHandler
Event Type
Type Description
Windows.Foundation.TypedEventHandler<PdfView, Document>

OnBeforeDocumentOpening

This is called right before a document starts getting opened.
It is useful for any needed Controller changes when opening a document through the PdfView XAML, or any other way where the InitializationCompletedHandler might happen too late on the lifecycle to accomodate these changes.
As it passes in a Windows.Foundation.Deferral, you must call Windows.Foundation.Deferral.Complete to make sure execution continues.

Declaration
public event TypedEventHandler<PdfView, Deferral> OnBeforeDocumentOpening
Event Type
Type Description
Windows.Foundation.TypedEventHandler<PdfView, Windows.Foundation.Deferral>

OnDocumentOpened

The event handler invoked whenever a document is opened.

Declaration
public event TypedEventHandler<PdfView, Document> OnDocumentOpened
Event Type
Type Description
Windows.Foundation.TypedEventHandler<PdfView, Document>

OnFileExported

This event handler is invoked whenever a document is exported successfully to a Windows.Storage.StorageFile.

Declaration
public event TypedEventHandler<PdfView, StorageFile> OnFileExported
Event Type
Type Description
Windows.Foundation.TypedEventHandler<PdfView, Windows.Storage.StorageFile>

OnFileExportFailed

This event handler is invoked whenever a document failed to export to a Windows.Storage.StorageFile.

Declaration
public event TypedEventHandler<PdfView, Exception> OnFileExportFailed
Event Type
Type Description
Windows.Foundation.TypedEventHandler<PdfView, System.Exception>

OnSuspendUnloading

The event handler is invoked whenever the PdfView is about to unload and suspends closing of the document. You must call Windows.Foundation.Deferral.Complete on the Windows.Foundation.Deferral once finished.

Declaration
public event TypedEventHandler<PdfView, Deferral> OnSuspendUnloading
Event Type
Type Description
Windows.Foundation.TypedEventHandler<PdfView, Windows.Foundation.Deferral>

OnViewModeChange

Event handler for the PdfViewMode changes.

Declaration
public event TypedEventHandler<PdfView, PdfViewModeChange> OnViewModeChange
Event Type
Type Description
Windows.Foundation.TypedEventHandler<PdfView, PdfViewModeChange>

OnViewStateChanged

This event is invoked whenever the view state changes.

Declaration
public event TypedEventHandler<Controller, ViewState> OnViewStateChanged
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, ViewState>

OnWatermarkRequested

Use this event handler to set a Watermark for the view. In the handler set the watermark property ViewWatermark. You must call Completed on the Windows.Foundation.Deferral once finished.

Declaration
public event TypedEventHandler<Controller, Deferral> OnWatermarkRequested
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, Windows.Foundation.Deferral>

Implements

Windows.UI.Composition.IAnimationObject
Windows.UI.Composition.IVisualElement