Working with page navigation

Navigation between the pages of the PDF document can be achieved using the GotoPage method or using the commands.

The following code snippet explains the page navigation using the GotoPage Method.

// Navigates to the page 5 in the PDF document.
pdfViewer.GotoPage(5);
Navigates to the page 5 in the PDF document.
pdfViewer.GotoPage(5)

The following commands can also be used for page navigation:

Names Description
FirstPageCommand Goes to the first page.
LastPageCommand Goes to the last page.
PreviousPageCommand Goes to the previous page.
NextPageCommand Goes to the next page.
GoToPageCommand Goes to the specified page.

FirstPageCommand

Navigation to the first page can be achieved by using the FirstPageCommand as shown below.

<Button Command="{Binding FirstPageCommand}" />

LastPageCommand

Navigation to the last page can be achieved by using the LastPageCommand as shown below.

<Button Command="{Binding LastPageCommand}" />

NextPageCommand

NextPageCommand displays the page next to the currently displayed page in the PDF Viewer.

<Button Command="{Binding NextPageCommand}" />

PreviousPageCommand

PreviousPageCommand displays the page previous to the currently displayed page in the PDF Viewer.

<Butston Command="{Binding PreviousPageCommand}" />

GoToPageCommand

This predefined command displays the specified page.

<Button Command="{Binding GoToPageCommand}" CommandParameter="{Binding Path=Text, ElementName=PageNumberTextBox}" />

Events associated with the Page Navigation:

Name Description Arguments Type
PageChanged Triggers when the specified page is rendered. PageChangedEventArgs EventHandler

PageChanged Event

This event is triggered when there is a change in the page being displayed in the PDF Viewer.

The following code snippet updates the current page number in a text block, whenever the page is changed.

private void PdfViewer_PageChanged(object sender, PageChangedEventArgs e)
{
    pageNumberTextBlock.Text = e.NewPageNumber.ToString();
}
Private Sub PdfViewer_PageChanged(sender As Object, e As PageChangedEventArgs) Handles pdfViewer.PageChanged
    pageNumberTextBlock.Text = e.NewPageNumber.ToString()
End Sub