Customizing Page Navigation in Our iOS Viewer

After loading a PDF document, you can programmatically interact with it, which allows you to scroll to different pages or zoom in and out. All of the interaction APIs are available on PDFViewController, which is the core PDF viewer.

Changing the Current Page

A user can manually change the current page by swiping on a device. However, you can programmatically change pages using pageIndex and setPageIndex(_:animated:). You can also use pageIndex to fetch the current page:

let startPage = pdfController.pageIndex

// Change to page 13 (zero-based page numbers).
pdfController.pageIndex = 12

// Go to the last page using a transitioning animation.
let lastPage = document.pageCount - 1
pdfController.setPageIndex(lastPage, animated: true)

// Go back to the page where you started.
pdfController.pageIndex = startPage
NSUInteger startPage = pdfController.pageIndex;

// Change to page 13 (zero-based page numbers).
pdfController.pageIndex = 12;

// Go to the last page using a transitioning animation.
NSUInteger lastPage = document.pageCount - 1;
[pdfController setPageIndex:lastPage animated:YES];

// Go back to the page where you started.
pdfController.pageIndex = startPage;