Skip to main content

Navigation, zoom and search

Important

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
CurrentPageCurrent page number, 1-based. Bindable in both directions.
GoToPage(int pageNumber)Navigates to the specified page.
NextPage(), PreviousPage()Navigates one page forward or back.
GetPageLabel(int pageNumber)Returns 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 are 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
ZoomLevelZoom 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 to the zoom.
ZoomChangedRaised when the zoom level changes.

Gestures​

On touch devices and trackpads, the control handles the following gestures:

  • Pinch to zoom
  • Swipe between pages (in SinglePage and TwoPages view modes)
  • Long press for contextual menu

GetOutline() returns the document's table of contents as a tree of PdfBookmark items, each with a Title, optional PageIndex, Children and 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()Returns the document's table of contents.
GoToBookmark(PdfBookmark)Navigates to an outline entry. This is its destination (page plus position) when it has one, else its page.
NavigateTo(PdfLinkDestination)Navigates to a page destination, including its position and zoom if specified by the destination. Returns false for URI and file destinations.

Links in the document are clickable. When clicking a link, LinkClicked is raised. The target isDestination, 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);
}
};

Bookmarks​

User bookmarks are separate from the document outline. They are stored in the PDF itself. The sidebar lists them in the Bookmarks tab when IsBookmarksEnabled is true.

ShowBookmarkIndicators draws a ribbon on bookmarked pages and thumbnails.

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

MemberDescription
IsPageBookmarked(int pageNumber)Whether the specified page is bookmarked.
AddBookmark(int pageNumber), RemoveBookmark(int pageNumber), ToggleBookmark(int pageNumber)Changes the bookmark status of 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.

Each individual PdfSearchResult has a PageIndex, CharIndex and CharCount of the match, and its Bounds on the page.

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)Searches the document, with the option to cancel. A cancelled search stops within a page. Returns the matches up till cancellation and highlights them on the pages.
FindNext(), FindPrevious()Moves the active match.
ClearSearch()Clears the matches and their highlights.
SearchResultsMatches of a search.
SearchResultCountNumber of matches.
CurrentSearchResultIndexIndex of the active match.
SearchCompletedRaised when a search finishes.

Search options​

The following SearchOptions are available. The toolbar search box is bound to SearchQuery, SearchMatchCase and SearchMatchWholeWord.

  • MatchCase: Search matches uppercase/lowercase.
  • MatchWholeWord: Search matches whole words.
  • StartPage: A 0-based page index.
  • MaxResults: Set 0 for unlimited results.
var results = await Viewer.SearchAsync("invoice", new SearchOptions
{
MatchCase = false,
MatchWholeWord = true,
});

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

Text selection​

Text selection cannot span pages. Setting AllowTextSelection to false disables selection entirely.

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

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, SelectedTextCurrent selection state.

Text extraction and page images​

These members take 0-based page indexes.

MemberDescription
GetPageTextAsync(int pageIndex, CancellationToken)Extracts the plain text of the specified page. 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 the specified 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.
// Create a thumbnail of the first page for a file list
using var thumbnail = await Viewer.RenderPageToImageAsync(0, scale: 0.25);
tip

Dispose the bitmap after running RenderPageToImageAsync.

Keyboard shortcuts​

Most shortcuts are enabled only when EnableKeyboardShortcuts is true. Set to false to keep these keystrokes for your own commands. Similarly, combinations not used by PdfViewer, such as Ctrl+Shift+A, can be used by your own handlers.

See Always on for exceptions that are unaffected by EnableKeyboardShortcuts.

Shortcuts in the tables below are listed with the Ctrl key. Unless otherwise specified, this can be directly substituted with Cmd on macOS.

ShortcutActionNotes
Ctrl+CCopy the selected text or annotation.Only handled when something is selected.
Ctrl+VPaste the copied annotation onto the current page.Needs a copied annotation and CanEditAnnotations.
Ctrl+ASelect all text on the current page.
Ctrl++Zoom inAlternatives are = and the numeric keypad +.
Ctrl+-Zoom outAlternatives are _ and the numeric keypad -.
Ctrl+0Adjust zoom to actual size (100%).
Ctrl+1Adjust zoom to fit page.
Ctrl+2Adjust zoom to fit width.
Ctrl+DBookmark the current page.Add only. Does not remove.
Ctrl+ZUndo
Windows: Ctrl+Y, macOS: Cmd+Shift+ZRedo
Ctrl+SSave to Source.Only when the document can be saved. Otherwise left to the host.
Delete, BackspaceDelete the selected annotation.Needs CanEditAnnotations. Undoable.
Arrow keysNudge the selected annotation by 1 px.Can be disabled with IsArrowKeyNudgeEnabled.
Shift + arrow keysNudge the selected annotation by 10 px.Can be disabled with IsArrowKeyNudgeEnabled.
↑, ↓Scroll in the continuous view modes.
← / ↑, → / ↓Previous / next page in single and two-page view modes.

Always on​

These keyboard shortcuts are always enabled and cannot be disabled by setting EnableKeyboardShortcuts to false.

ShortcutAction
EscCloses the contextual menu, clears the annotation or text selection, deactivates the active tool. Only marked handled when something changed.
Esc in a form fieldLeaves form focus.
Tab / Shift+Tab in the viewerEnters the first / last form field on the current page.
Tab / Shift+Tab in a form fieldNext / previous form field. Leaves the viewer when there is no next field.
Ctrl+A in a form fieldSelect all text in the form field.
Ctrl+C in a form fieldCopy text in the form field.
Ctrl+X in a form fieldCut text in the form field.
Ctrl+V in a form fieldPaste text into the form field.
Ctrl+Z in a form fieldUndo inside the form field.
Windows: Ctrl+Y, macOS: Cmd+Shift+Z in a form fieldRedo inside the form field.

Inside the PDF viewer's chrome​

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

WhereShortcutAction
Inline text editor (text box or shape text)EscCancel
Ctrl+EnterCommit
Search boxEnterNext result
EscClear and close
Page number boxEnterCommit
EscRevert
Link URL dialog, password, go-to-page, custom zoom overlaysEnterCommit
EscCancel
Hex color inputEnterApply color

See also​