Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Page Navigation ​

After loading a PDF document, you can programmatically interact with it, which allows you to view and transition between the pages like scrolling and jumping to specific pages.

javascript
// Previous page.
documentViewer.setCurrentPage(documentViewer.getCurrentPage() - 1);

// Next page.
documentViewer.setCurrentPage(documentViewer.getCurrentPage() + 1);

// Jump to a page.
documentViewer.setCurrentPage(3);

If you want to receive notifications when page numbers change, you can listen for the pageNumberUpdated event of documentViewer.

Scroll ​

To scroll to specific distances in the horizontal and vertical directions, you can call scrollTo on the scroll element returned by documentViewer.getScrollViewElement().

javascript
// Top and left are optional.
const scrollElement = documentViewer.getScrollViewElement();
scrollElement.scrollTo({
  top: 200,
  left: 100
});

To scroll a certain percentage of distance horizontally or vertically, you can calculate the position from the size of the scroll element.

javascript
// Top and left are optional.
const percent = { top: 20, left: 50 };
const scrollElement = documentViewer.getScrollViewElement();
scrollElement.scrollTo({
  top: (scrollElement.scrollHeight - scrollElement.clientHeight) * percent.top / 100,
  left: (scrollElement.scrollWidth - scrollElement.clientWidth) * percent.left / 100
});

Scroll Mode ​

ComPDF for Web has two scrolling modes: Vertical and Horizontal. You can set the corresponding mode by using the following method.

javascript
instance.UI.setScrollMode(mode);

This is the parameters to apply different scroll modes.

NameRequiredTypeDescription
modeyesstringScroll Mode Parameter, Vertical: 'Vertical', Horizontal: 'Horizontal'

Thumbnails ​

Provide methods to render PDF pages as thumbnail images.