Skip to main content

Navigation, zoom and search

note

Navigation members use 1-based page numbers, matching CurrentPage and the page box in the toolbar. Annotation, text extraction and rendering members use 0-based page indexes.

MemberDescription
CurrentPageThe current page number, 1-based. Bindable in both directions.
GoToPage(int pageNumber)Navigates to a page.
NextPage() / PreviousPage()Navigates forward or back.
GetPageLabel(int pageNumber)The page's label from the document, such as iv or A-2, or null when it has none. Thumbnails and the page box use labels when present.
PageChangedRaised when the current page changes. Args include OldPage and NewPage.
Viewer.PageChanged += (_, e) =>
StatusText = $"Page {e.NewPage} of {Viewer.PageCount}";

View modes

ViewMode selects how pages are laid out.

ValueDescription
SinglePageOne page at a time. Arrow keys and swipes move between pages.
ContinuousPages in a vertical scrolling column. Only pages near the viewport are decoded.
TwoPagesTwo pages side by side.
TwoPagesContinuousTwo pages side by side in a scrolling column.

Zoom

MemberDescription
ZoomLevelThe zoom factor. 1.0 is 100%. Bindable in both directions.
ZoomModeManual, FitWidth, FitPage, FitHeight or ActualSize.
MinZoom / MaxZoomZoom bounds.
ZoomStepIncrement used by ZoomIn and ZoomOut. 0 uses the built-in adaptive step.
ZoomIn() / ZoomOut() / ResetZoom()Adjusts the zoom.
FitWidth() / FitPage() / FitHeight()Applies a fit mode.
ZoomChangedRaised when the zoom level changes.

Pinch to zoom, swipe between pages in the single and two-page modes, and long-press for the context menu are handled by the control on touch and trackpad.

GetOutline() returns the document's table of contents as a tree of PdfBookmark items, each with a Title, an optional PageIndex, Children and an optional Destination. The sidebar shows it in the Table of Contents tab when IsTableOfContentsEnabled is true. HasOutline reports whether the document has one.

MemberDescription
GetOutline()The document's table of contents.
GoToBookmark(PdfBookmark)Navigates to an outline entry: its destination (page plus position) when it has one, else its page.
NavigateTo(PdfLinkDestination)Navigates to a page destination, including its position and zoom when the destination specifies them. Returns false for URI and file destinations.

Links in the page are clickable. LinkClicked is raised first, with the target in Destination, which is a PdfLinkDestination.PageDestination, UriDestination or FileDestination. Unless a handler sets Handled to true:

  • A page destination navigates within the document.
  • An http, https or mailto URI opens in the system browser or mail client after the user confirms.
  • File destinations and other URI schemes are raised but never opened by the viewer.
Viewer.LinkClicked += (_, e) =>
{
if (e.Destination is PdfLinkDestination.UriDestination uri
&& uri.Uri.StartsWith("myapp:"))
{
e.Handled = true;
HandleDeepLink(uri.Uri);
}
};

User bookmarks

User bookmarks are separate from the document outline. They are stored in the PDF itself, in the format macOS Preview uses, so both applications see the same bookmarks. The sidebar lists them in the Bookmarks tab when IsBookmarksEnabled is true, and ShowBookmarkIndicators draws a ribbon on bookmarked pages and thumbnails.

MemberDescription
IsPageBookmarked(int pageNumber)Whether the page is bookmarked.
AddBookmark(int pageNumber) / RemoveBookmark(int pageNumber) / ToggleBookmark(int pageNumber)Changes the bookmark on a page. Returns whether anything changed.
ToggleBookmarkCurrentPage()Toggles the bookmark on the current page.
HasBookmarksWhether the document has any user bookmarks.
BookmarksChangedRaised after any change.

Bookmark changes are written by the next save and are not part of the undo history.

MemberDescription
SearchAsync(string query, SearchOptions? options = null)Searches the document. Returns the matches and highlights them on the pages.
SearchAsync(string query, SearchOptions? options, CancellationToken)The same with cancellation. Matches appear page by page as the search runs.
FindNext() / FindPrevious()Moves the active match.
ClearSearch()Clears the matches and their highlights.
SearchResultsThe matches of the last search.
SearchResultCountThe number of matches.
CurrentSearchResultIndexThe index of the active match.
SearchCompletedRaised when a search finishes.

SearchOptions has MatchCase, MatchWholeWord, StartPage (a 0-based page index) and MaxResults (0 for unlimited). Each PdfSearchResult has a PageIndex, the CharIndex and CharCount of the match, and its Bounds on the page.

The toolbar search box is bound to SearchQuery, SearchMatchCase and SearchMatchWholeWord.

var results = await Viewer.SearchAsync("invoice", new SearchOptions
{
MatchCase = false,
MatchWholeWord = true,
});

Console.WriteLine($"{results.Count} matches");
Viewer.FindNext();

Text selection

A selection cannot span pages. AllowTextSelection turns selection off entirely.

MemberDescription
SelectAll()Selects all text on the current page.
ClearSelection()Clears the selection.
GetSelectedText()Returns the selected text.
CopySelectionToClipboard()Copies the selection to the clipboard.
HasSelection / SelectedTextThe current selection state.

Selecting text shows a context menu with Copy and the text markup tools. See Annotations.

Text extraction and page images

These members take 0-based page indexes.

MemberDescription
GetPageTextAsync(int pageIndex, CancellationToken)Extracts one page's plain text. Returns an empty string when no document is loaded or the index is out of range.
GetTextAsync(CancellationToken)Extracts the whole document's text, one string per page.
RenderPageToImageAsync(int pageIndex, double scale = 1.0, CancellationToken)Renders a page to a Bitmap at the given scale, where 1.0 is 100%. Returns null when no document is loaded or the index is out of range. Dispose the bitmap when you are done with it.
// A thumbnail of the first page for a file list
using var thumbnail = await Viewer.RenderPageToImageAsync(0, scale: 0.25);

Keyboard shortcuts

Cmd is on macOS and iOS and Ctrl everywhere else. Modifiers are matched exactly, so a combination the viewer does not list, such as Cmd+Shift+A, reaches your own handlers.

Document shortcuts

These require EnableKeyboardShortcuts. Set it to false to keep these keystrokes for your own commands. Form input and Esc are unaffected.

ShortcutActionNotes
Cmd+CCopy the selected annotation, else the selected textOnly handled when something is selected
Cmd+VPaste the copied annotation onto the current pageNeeds a copied annotation and CanEditAnnotations
Cmd+ASelect all text on the current page
Cmd++Zoom in= and the numeric keypad + also work
Cmd+-Zoom out_ and the numeric keypad - also work
Cmd+0Actual size (100%)
Cmd+1Fit page
Cmd+2Fit width
Cmd+DBookmark the current pageAdd only. Remove from the Bookmarks tab or the API
Cmd+ZUndo
Cmd+Shift+Z, Ctrl+YRedo
Cmd+SSave to SourceOnly when the document can be saved, otherwise left to the host
Delete, BackspaceDelete the selected annotationNeeds CanEditAnnotations. Undoable
Arrow keysNudge the selected annotation by 1 pxShift nudges 10 px. Opt out with IsArrowKeyNudgeEnabled
/ Scroll in the continuous view modes
/ , / Previous / next page in the single and two-page modes

Always on

These are not affected by EnableKeyboardShortcuts.

ShortcutAction
EscCloses the context menu, clears the annotation or text selection, deactivates the active tool. Only marked handled when something changed
Tab / Shift+Tab onto the viewerEnters the first / last form field on the current page
Tab / Shift+Tab in a form fieldNext / previous field. Leaves the viewer when there is no next field
Esc in a form fieldLeaves form focus
Cmd+A, Cmd+C, Cmd+X, Cmd+V in a form fieldSelect all, copy, cut and paste the field's text
Cmd+Z, Cmd+Shift+Z in a form fieldUndo and redo inside the field

Inside the viewer's own chrome

WhereKeys
Inline text editor (text box or shape text)Esc cancels, Ctrl+Enter commits
Search boxEnter goes to the next result, Esc clears and closes
Page number boxEnter commits, Esc reverts
Link URL dialog, password, go-to-page and custom zoom overlaysEnter confirms, Esc cancels
Hex colour inputsEnter applies

FocusViewer() moves keyboard focus to the viewer so the shortcuts apply.

See also