Class Controller

The class that controls the UI of a PdfView or a manually registered Windows.UI.Xaml.Controls.WebView

Inheritance
System.Object
Controller
Namespace: PSPDFKit.UI
Assembly: PSPDFKit.dll
Syntax
public sealed class Controller

Constructors

Controller(WebView2, Uri)

Constructs a Controller to control an query the state of the UI.

Declaration
public Controller(WebView2 webView, Uri css)
Parameters
Type Name Description
Microsoft.UI.Xaml.Controls.WebView2 webView

A Windows.UI.Xaml.Controls.WebView that has loaded 'PSPDFKit.js'

System.Uri css

Optional URI of alternative CSS for 'PSPDFKit.js. See https://pspdfkit.com/guides/web/current/customizing-the-interface/css-customization/?search=css

Properties

AutoSave

The auto save mode. AutoSaveMode.

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

ElectronicSignatureStorage

The storage handling signature saving. By default, signatures are not saved.
You can implement IElectronicSignatureStorage to customize the storing behavior, or use the sample InMemoryElectronicSignatureStorage.

Declaration
public IElectronicSignatureStorage ElectronicSignatureStorage { get; set; }
Property Value
Type Description
IElectronicSignatureStorage

ViewState

The current ViewState of the UI. Use with ShowDocumentWithViewStateAsync(DocumentSource, ViewState) to open a new document with the current ViewState.

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

ViewWatermark

A watermark which will be overlaid on the pages in the view. Set to null for no watermark. Usually the best place to set this is in PSPDFKit.UI.Controller.OnBeforeWatermark.

Declaration
public Watermark ViewWatermark { get; set; }
Property Value
Type Description
Watermark

Methods

AddStoredSignatureAsync(IAnnotation)

Adds a signature to the existing list. The signature can be in the form of either Ink or Image annotations.

Declaration
public IAsyncAction AddStoredSignatureAsync(IAnnotation signature)
Parameters
Type Name Description
IAnnotation signature
Returns
Type Description
Windows.Foundation.IAsyncAction

DisableAnnotationPresetUpdatingAsync(Boolean)

If annotation preset updating is disabled then any changes to the defaults made by the user will not be preserved after they are finished with the annotation. In addition, the event OnAnnotationPresetUpdate will not be fired.

Declaration
public IAsyncAction DisableAnnotationPresetUpdatingAsync(bool disableUpdates)
Parameters
Type Name Description
System.Boolean disableUpdates

true disables preset updating. false enables preset updating.

Returns
Type Description
Windows.Foundation.IAsyncAction

GetAnnotationPresetsAsync()

Get the current map of annotation presets.

Declaration
public IAsyncOperation<IDictionary<string, IAnnotation>> GetAnnotationPresetsAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IDictionary<System.String, IAnnotation>>

A map of annotation preset name to an instance of IAnnotation with the settings.

GetCurrentLocaleAsync()

Gets the code for the current view locale.

Declaration
public IAsyncOperation<string> GetCurrentLocaleAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.String>

Current view locale code.

GetCurrentPageIndexAsync()

The page index of the page that's currently visible. If there is more than one page visible this will return the page that is using the most space in the viewport. The page index is zero-based and has a maximum value of the Document's TotalPageCount - 1.

Declaration
public IAsyncOperation<int> GetCurrentPageIndexAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Int32>

A page index

GetInkSignaturesAsync()

Gets current set of ink signatures as a list of Ink annotations. See IAnnotation

Declaration
[Obsolete("The GetInkSignaturesAsync method has been made obsolete in favor of Controller.GetStoredSignaturesAsync and will be removed in a future release.")]
public IAsyncOperation<IList<IAnnotation>> GetInkSignaturesAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<IAnnotation>>

A list of Ink annotations.

GetInteractionModeAsync()

Gets the currently set InteractionMode

Declaration
public IAsyncOperation<InteractionMode> GetInteractionModeAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<InteractionMode> InteractionMode

GetLayoutModeAsync()

Gets the currently set LayoutMode.

Declaration
public IAsyncOperation<LayoutMode> GetLayoutModeAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<LayoutMode>

The LayoutMode

GetPdfDocument()

Get the currently opened Document

Declaration
public Document GetPdfDocument()
Returns
Type Description
Document

GetScrollModeAsync()

Gets the currently set ScrollMode.

Declaration
public IAsyncOperation<ScrollMode> GetScrollModeAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<ScrollMode>

The ScrollMode

GetSelectedAnnotationAsync()

If an annotation is currently selected (and as well being either created or editable), this function will return the annotation.

Declaration
public IAsyncOperation<IAnnotation> GetSelectedAnnotationAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<IAnnotation>

The currently selected annotation or null if none is selected.

GetSidebarModeAsync()

Gets the currently set SidebarMode

Declaration
public IAsyncOperation<SidebarMode> GetSidebarModeAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<SidebarMode> SidebarMode

GetSidebarPlacementAsync()

Gets the currently set SidebarPlacement.

Declaration
public IAsyncOperation<SidebarPlacement> GetSidebarPlacementAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<SidebarPlacement> SidebarPlacement

GetStoredSignaturesAsync()

Gets current set of signatures as a list of Ink and Image annotations. See IAnnotation

Declaration
public IAsyncOperation<IList<IAnnotation>> GetStoredSignaturesAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<IAnnotation>>

A list of Ink and Image annotations.

GetSupportedLocalesAsync()

Gets the codes of all supported view locales.

Declaration
public IAsyncOperation<IEnumerable<string>> GetSupportedLocalesAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IEnumerable<System.String>>

An IEnumerable containing all locale codes currently supported.

GetTextSelectionAsync()

Gets a TextBlock representing the current text selection.

Declaration
public IAsyncOperation<TextBlock> GetTextSelectionAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<TextBlock>

A TextBlock or null if no text is selected.

GetToolbarItems()

Gets the IToolbarItems shown.

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

Current list of toolbar items

GetZoomModeAsync()

Gets the currently set ZoomMode

Declaration
public IAsyncOperation<ZoomMode> GetZoomModeAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<ZoomMode> ZoomMode

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

IsKeepFirstSpreadAsSinglePageAsync()

Is the first spread always showing a single page?

Declaration
public IAsyncOperation<bool> IsKeepFirstSpreadAsSinglePageAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Boolean>

true or false

IsKeepSelectedToolAsync()

Is selected tool maintaining its selected state after an annotation is created?

Declaration
public IAsyncOperation<bool> IsKeepSelectedToolAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Boolean>

true or false

IsPrintingAllowedAsync()

Is the printing button in the toolbar enabled or disabled?

Declaration
public IAsyncOperation<bool> IsPrintingAllowedAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Boolean>

true or false

IsReadOnlyAsync()

Is read only mode is activated?

Declaration
public IAsyncOperation<bool> IsReadOnlyAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Boolean>

true or false

IsShowingAnnotationsAsync()

Are annotations being rendered?

Declaration
public IAsyncOperation<bool> IsShowingAnnotationsAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Boolean>

true or false

IsShowingToolbarAsync()

Is the toolbar displayed?

Declaration
public IAsyncOperation<bool> IsShowingToolbarAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<System.Boolean>

true or false

RemoveStoredSignatureAsync(IAnnotation)

Removes a specific signature from the stored list. This signature can be in the form of either Ink or Image annotations.

Declaration
public IAsyncAction RemoveStoredSignatureAsync(IAnnotation signature)
Parameters
Type Name Description
IAnnotation signature

The signature you wish to remove.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetAnnotationCreatorNameAsync(String)

Whenever an annotation is created, it will use the currently set string as its CreatorName.
This is set for the whole PdfView, and will persist when changing documents.
Setting it to null or an empty string will remove the previously set creator name.

Declaration
public IAsyncAction SetAnnotationCreatorNameAsync(string creatorName)
Parameters
Type Name Description
System.String creatorName

The desired creator name.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetAnnotationPresetAsync(String, IAnnotation)

Set an annotation preset.

Declaration
public IAsyncAction SetAnnotationPresetAsync(string preset, IAnnotation settings)
Parameters
Type Name Description
System.String preset

The name of the preset.

IAnnotation settings

The annotation settings.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetAnnotationPresetsAsync(IDictionary<String, IAnnotation>)

Set the current map of annotation presets.

Declaration
public IAsyncAction SetAnnotationPresetsAsync(IDictionary<string, IAnnotation> presets)
Parameters
Type Name Description
System.Collections.Generic.IDictionary<System.String, IAnnotation> presets

A System.Collections.Generic.IDictionary<TKey, TValue> of presets.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetAnnotationToolbarItemsAsync(AnnotationType, IList<IAnnotationToolbarItem>)

Sets the IAnnotationToolbarItems to be show. 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

SetCurrentPageIndexAsync(Int32)

Display the page at the specified index.

Declaration
public IAsyncAction SetCurrentPageIndexAsync(int pageIndex)
Parameters
Type Name Description
System.Int32 pageIndex

The zero-based index of the page to be displayed.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetInkSignaturesAsync(IList<IAnnotation>)

Sets current set of ink signatures.

Declaration
[Obsolete("The SetInkSignaturesAsync method has been made obsolete in favor of Controller.SetStoredSignaturesAsync and will be removed in a future release.")]
public IAsyncAction SetInkSignaturesAsync(IList<IAnnotation> inkSignatures)
Parameters
Type Name Description
System.Collections.Generic.IList<IAnnotation> inkSignatures
Returns
Type Description
Windows.Foundation.IAsyncAction

SetInteractionModeAsync(InteractionMode)

Sets the current InteractionMode and gives focus to the Windows.UI.Xaml.Controls.WebView. Use this method to set a specific interaction mode.

Declaration
public IAsyncAction SetInteractionModeAsync(InteractionMode interactionMode)
Parameters
Type Name Description
InteractionMode interactionMode InteractionMode
Returns
Type Description
Windows.Foundation.IAsyncAction

SetKeepFirstSpreadAsSinglePageAsync(Boolean)

When this is enabled, the first spread will always show a single page, even when PSPDFKit.LayoutMode.Double is enabled. This is useful for magazines that want to show a cover page before the regular content starts.

Declaration
public IAsyncAction SetKeepFirstSpreadAsSinglePageAsync(bool keepFirstSpreadAsSinglePage)
Parameters
Type Name Description
System.Boolean keepFirstSpreadAsSinglePage
Returns
Type Description
Windows.Foundation.IAsyncAction

SetKeepSelectedToolAsync(Boolean)

Set selected tool to maintain its selected state after an annotation is created

Declaration
public IAsyncAction SetKeepSelectedToolAsync(bool keepSelectedTool)
Parameters
Type Name Description
System.Boolean keepSelectedTool
Returns
Type Description
Windows.Foundation.IAsyncAction

SetLayoutModeAsync(LayoutMode)

Changes how the pages are be laid out in the document view.

Declaration
public IAsyncAction SetLayoutModeAsync(LayoutMode layoutMode)
Parameters
Type Name Description
LayoutMode layoutMode LayoutMode
Returns
Type Description
Windows.Foundation.IAsyncAction

SetLocaleAsync(String)

Changes the locale for the view. This is useful for changing language at runtime while a document is opened.
For setting it before opening a document, the Locale property is more appropriate.

A list of locale codes can be found in our Localization documentation or at runtime through GetSupportedLocalesAsync().

Declaration
public IAsyncAction SetLocaleAsync(string localeCode)
Parameters
Type Name Description
System.String localeCode

The short code for the desired locale.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetPrintingAllowedAsync(Boolean)

Control whether or not the printing button in the toolbar should be disabled.

Declaration
public IAsyncAction SetPrintingAllowedAsync(bool allowPrinting)
Parameters
Type Name Description
System.Boolean allowPrinting
Returns
Type Description
Windows.Foundation.IAsyncAction

SetReadOnlyAsync(Boolean)

When the read only mode is activated, the Controller for creating, updating and deleting annotations will be completely hidden. In addition, the user will also no longer be able to select annotations.

Declaration
public IAsyncAction SetReadOnlyAsync(bool readOnly)
Parameters
Type Name Description
System.Boolean readOnly
Returns
Type Description
Windows.Foundation.IAsyncAction

SetScrollModeAsync(ScrollMode)

Changes the mode of page scrolling in the document view - either continuous or per spread (paginated).

Declaration
public IAsyncAction SetScrollModeAsync(ScrollMode scrollMode)
Parameters
Type Name Description
ScrollMode scrollMode ScrollMode
Returns
Type Description
Windows.Foundation.IAsyncAction

SetSelectedAnnotationAsync(IAnnotation)

Selects an annotation in the user interface. If the annotation is null, the current selection will be cleared instead.

Declaration
public IAsyncAction SetSelectedAnnotationAsync(IAnnotation annotation)
Parameters
Type Name Description
IAnnotation annotation

The annotation you want to set as selected. If null the current selection will be cleared instead.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetShowAnnotationsAsync(Boolean)

When this is set to false, annotations will no longer be rendered. This option can alo be set to false, when ReadOnly mode is enabled.

Declaration
public IAsyncAction SetShowAnnotationsAsync(bool showAnnotations)
Parameters
Type Name Description
System.Boolean showAnnotations
Returns
Type Description
Windows.Foundation.IAsyncAction
See Also

SetShowToolbarAsync(Boolean)

Set this to true if you want a toolbar for navigation and annotation controls or false if you don't.

Declaration
public IAsyncAction SetShowToolbarAsync(bool showToolbar)
Parameters
Type Name Description
System.Boolean showToolbar
Returns
Type Description
Windows.Foundation.IAsyncAction

SetSidebarModeAsync(SidebarMode)

Sets the current SidebarMode. Use this method to set a specific sidebar mode.

Declaration
public IAsyncAction SetSidebarModeAsync(SidebarMode sidebarMode)
Parameters
Type Name Description
SidebarMode sidebarMode SidebarMode
Returns
Type Description
Windows.Foundation.IAsyncAction

SetSidebarPlacementAsync(SidebarPlacement)

Sets the current SidebarPlacement.

Declaration
public IAsyncAction SetSidebarPlacementAsync(SidebarPlacement sidebarPlacement)
Parameters
Type Name Description
SidebarPlacement sidebarPlacement SidebarPlacement
Returns
Type Description
Windows.Foundation.IAsyncAction

SetStoredSignaturesAsync(IList<IAnnotation>)

Sets current set of signatures. These can be in the form of either Ink or Image annotations.

Declaration
public IAsyncAction SetStoredSignaturesAsync(IList<IAnnotation> signatures)
Parameters
Type Name Description
System.Collections.Generic.IList<IAnnotation> signatures
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.

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

SetViewStateAsync(ViewState)

Sets the ViewState.

Declaration
public IAsyncAction SetViewStateAsync(ViewState viewState)
Parameters
Type Name Description
ViewState viewState
Returns
Type Description
Windows.Foundation.IAsyncAction

SetZoomFactorAndScrollAsync(Single, Single, Single)

Changes the current ZoomMode to ZoomFactor and sets the current zoom factor. Also moves the scroll bars if appropriate.

Declaration
public IAsyncAction SetZoomFactorAndScrollAsync(float zoomFactor, float scrollLeft, float scrollTop)
Parameters
Type Name Description
System.Single zoomFactor

A zoom multiplier.

System.Single scrollLeft

The fractional position of the horizontal scrollbar.

System.Single scrollTop

The fractional position of the vertical scrollbar.

Returns
Type Description
Windows.Foundation.IAsyncAction

SetZoomModeAsync(ZoomMode)

Sets the current zoom factor. Use this method to set a specific zoom mode.

Declaration
public IAsyncAction SetZoomModeAsync(ZoomMode zoomMode)
Parameters
Type Name Description
ZoomMode zoomMode ZoomMode
Returns
Type Description
Windows.Foundation.IAsyncAction

ShowDocumentAsync(DocumentSource)

Display the document in the UI. Note that this always resets CurrentPageIndex to 0.

Declaration
public IAsyncOperation<Document> ShowDocumentAsync(DocumentSource source)
Parameters
Type Name Description
DocumentSource source

The DocumentSource representing the PDF.

Returns
Type Description
Windows.Foundation.IAsyncOperation<Document>

A Document representing the opened PDF.

ShowDocumentAsync(DocumentSource, UInt32)

Display the document in the UI. Note that this always resets CurrentPageIndex to 0.

Declaration
public IAsyncOperation<Document> ShowDocumentAsync(DocumentSource source, uint maxDefaultZoomLevel)
Parameters
Type Name Description
DocumentSource source

The DocumentSource representing the PDF.

System.UInt32 maxDefaultZoomLevel

Sets the max possible zoom level. The default value is 10.

Returns
Type Description
Windows.Foundation.IAsyncOperation<Document>

A Document representing the opened PDF.

ShowDocumentWithViewStateAsync(DocumentSource, ViewState)

Display the document in the UI with all view options such as if annotations are show or not, and so on, reset to their default setting. Note that this always ignores CurrentPageIndex and sets it to 0.

Declaration
public IAsyncOperation<Document> ShowDocumentWithViewStateAsync(DocumentSource source, ViewState viewState)
Parameters
Type Name Description
DocumentSource source

The DocumentSource representing the PDF.

ViewState viewState

The ViewState to use when opening the PDF.

Returns
Type Description
Windows.Foundation.IAsyncOperation<Document>

A Document representing the opened PDF.

ShowDocumentWithViewStateAsync(DocumentSource, ViewState, UInt32)

Display the document in the UI with all view options such as if annotations are show or not, and so on, reset to their default setting. Note that this always ignores CurrentPageIndex and sets it to 0.

Declaration
public IAsyncOperation<Document> ShowDocumentWithViewStateAsync(DocumentSource source, ViewState viewState, uint maxDefaultZoomLevel)
Parameters
Type Name Description
DocumentSource source

The DocumentSource representing the PDF.

ViewState viewState

The ViewState to use when opening the PDF.

System.UInt32 maxDefaultZoomLevel

Sets the max possible zoom level. The default value is 10.

Returns
Type Description
Windows.Foundation.IAsyncOperation<Document>

A Document representing the opened PDF.

Events

IsEditableAnnotation

Occurs whenever the UI needs to determine if an annotation should be editable or not. Note that user interaction triggers this, but also internal UI calls, so multiple non-user driven triggers are expected.

Declaration
public event TypedEventHandler<Controller, AnnotationPermissionQuery> IsEditableAnnotation
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, AnnotationPermissionQuery>

OnAnnotationPresetUpdate

Invoked when an annotation preset is updated if DisableAnnotationPresetUpdatingAsync(Boolean) is not set to False.

Declaration
public event TypedEventHandler<Controller, AnnotationPresetUpdate> OnAnnotationPresetUpdate
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, AnnotationPresetUpdate>

OnAnnotationPressed

Invoked when an annotation is pressed, touched, or clicked by the user.

Declaration
public event TypedEventHandler<Controller, AnnotationPressedEventArgs> OnAnnotationPressed
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, AnnotationPressedEventArgs>

OnAnnotationSelectionChanged

Invoked when an annotation is being selected or unselected.

Declaration
public event TypedEventHandler<Controller, IAnnotation> OnAnnotationSelectionChanged
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, IAnnotation>

OnAnnotationsWillChange

Invoked whenever annotations are about to change. See AnnotationsWillChangeReason for the reasons.

Declaration
public event TypedEventHandler<Controller, AnnotationsChanging> OnAnnotationsWillChange
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, AnnotationsChanging>

OnCurrentPageChanged

Invoked when the currently displayed page changes. The page index of the page that's currently visible. If there is more than one page visible it is the page that is using the most space in the viewport.

Declaration
public event TypedEventHandler<Controller, int> OnCurrentPageChanged
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, System.Int32>

OnPagePressed

Invoked when the user presses, touches, or clicks on a page.

Declaration
public event TypedEventHandler<Controller, PagePressedEventArgs> OnPagePressed
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, PagePressedEventArgs>

OnPrint

Invoked when the print button is clicked on the toolbar in the UI.

Declaration
public event TypedEventHandler<Controller, Document> OnPrint
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, Document>

OnRequestPassword

Invoked when a password is required to open a PDF.

Declaration
public event TypedEventHandler<Controller, PasswordEventArgs> OnRequestPassword
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, PasswordEventArgs>

OnTextSelectionChanged

Invoked when the user changes the text selection. TextBlock represents the selected text, its location and dimensions. When text is deselected, the handler args is null.

Declaration
public event TypedEventHandler<Controller, TextBlock> OnTextSelectionChanged
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Controller, TextBlock>