Skip to main content
Version: Version 5

Interface: Document

Groups all the api actions related to the document.

Properties

goToPage()

goToPage: (viewerEl, pageNumber) => void

Triggers event to go to a page number.

Parameters

viewerEl: PdfToolsViewer

The viewer dom element.

pageNumber: number

The page number to go to.

Returns

void

Example

const viewerEl = document.querySelector('#viewer'); PdfToolsViewerApi.document.goToPage(viewerEl, 2);


nextPage()

nextPage: (viewerEl) => void

Triggers event to go to the next page.

Parameters

viewerEl: PdfToolsViewer

The viewer dom element.

Returns

void

Example

const viewerEl = document.querySelector('#viewer'); PdfToolsViewerApi.document.nextPage(viewerEl);


open()

open: (inputDocument) => void

Open a document.

Parameters

inputDocument: InputFile | InputUri

Input needed for opening the document.

Returns

void

Example

PdfToolsViewerApi.document.tools.open({ data: file });


previousPage()

previousPage: (viewerEl) => void

Triggers event to go to the previous page.

Parameters

viewerEl: PdfToolsViewer

The viewer dom element.

Returns

void

Example

const viewerEl = document.querySelector('#viewer'); PdfToolsViewerApi.document.previousPage(viewerEl);


rotate()

rotate: (viewerEl, newRotation) => void

Triggers event to rotate the document.

Parameters

viewerEl: PdfToolsViewer

The viewer dom element.

newRotation: Rotation

The new rotation to rotate it to.

Returns

void

Example

const viewerEl = document.querySelector('#viewer'); PdfToolsViewerApi.document.rotate(viewerEl, 90);


save()

save: (viewerEl, options) => void

Saves the current document as a PDF file and triggers a download.

Parameters

viewerEl: PdfToolsViewer

The Viewer DOM element.

options: DocumentSaveOptions

Options for configuring the document save behavior.

Returns

void

Example

const viewerEl = document.querySelector('#viewer'); PdfToolsViewerApi.document.save(viewerEl, options);


tools

tools: object

Groups all the api actions related to the document tools.

extractText

extractText: object

Groups all the api actions related to the document tools text extraction.

extractText.addEventListener()

addEventListener: (eventName, fn) => void

Add an event listener to the different events of extract text.

Parameters

eventName: "start" | "textExtracted"

fn: () => string | (txt) => void

The callback to execute.

Returns

void

Example

PdfToolsViewerApi.document.tools.extractText.addEventListener('start', () => { console.log('callback') });

extractText.start()

start: () => void

Trigger event indicating that the text extraction of the document tools has started.

Returns

void

Example

PdfToolsViewerApi.document.tools.extractText.start();

extractText.textExtracted()

textExtracted: (txt) => void

Trigger event indicating that text has been extracted.

Parameters

txt: string

The extracted text.

Returns

void

Example

PdfToolsViewerApi.document.tools.extractText.textExtracted('lorem ipsum');