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 : object

Constructors

Controller(WebView, Uri)

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

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

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

Windows.Foundation.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

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

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<IDictionary<System.String, IAnnotation>>

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

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
public IAsyncOperation<IList<IAnnotation>> GetInkSignaturesAsync()
Returns
Type Description
Windows.Foundation.IAsyncOperation<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

GetToolbarItems()

Gets the IToolbarItems shown.

Declaration
public IList<IToolbarItem> GetToolbarItems()
Returns
Type Description
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
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

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

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
IDictionary<System.String, IAnnotation> presets

A of presets.

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
public IAsyncAction SetInkSignaturesAsync(IList<IAnnotation> inkSignatures)
Parameters
Type Name Description
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

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

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

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
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

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.

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.

Events

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>

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>

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>

OnPrint

Invoked when the print putton 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>