Interface: Document
Groups all the API actions related to document handling.
Extends
Properties
deleteAnnotation()
deleteAnnotation: (
annotation) =>Promise<void>
Deletes the specified annotation from the document.
Parameters
annotation
The annotation to be deleted.
Returns
Promise<void>
Example
await viewer.document.deleteAnnotation(annotation);
download()
download: (
fileName,options?) =>Promise<void>
Downloads the current document.
Parameters
fileName
string
The name of the file to be downloaded (default is ‘download.pdf’).
options?
Document save options
Returns
Promise<void>
A promise that resolves when the document is downloaded.
Example
await viewer.document.download();
getAnnotations()
getAnnotations: () =>
Promise<Annotation[]>
Retrieves all annotations present in the current document.
Returns
Promise<Annotation[]>
A promise that resolves to an array of annotations.
Example
const annotations = await viewer.document.getAnnotations();
getThumbnail()
getThumbnail: (
pageNumber,options?) =>Promise<HTMLImageElement>
Retrieves a thumbnail image for a specific page in the document.
Parameters
pageNumber
number
The page number for which to retrieve the thumbnail image (1-based index).
options?
Options for thumbnail generation including dimensions and format.
Returns
Promise<HTMLImageElement>
A promise that resolves to the thumbnail image for the specified page.
Example
const thumbnail = await viewer.document.getThumbnail(1, { width: 100, height: 100 });
const defaultThumbnail = await viewer.document.getThumbnail(1); // Uses default options
const jpegThumbnail = await viewer.document.getThumbnail(1, { format: 'jpeg', quality: 0.8 });
getThumbnails()
getThumbnails: (
options?) =>Promise<HTMLImageElement[]>
Retrieves thumbnail images for all pages in the document.
Supports progressive rendering by using the onThumbnail callback and cancellation through signal.
Parameters
options?
Options for thumbnail generation including dimensions, format, and optional onThumbnail callback for progressive rendering and signal for cancellation.
Returns
Promise<HTMLImageElement[]>
A promise that resolves to an array of thumbnail images.
Example
// Basic usage
const thumbnails = await viewer.document.getThumbnails({ width: 100, height: 100 });
// Progressive rendering with callback
const abortController = new AbortController();
await viewer.document.getThumbnails({
width: 145,
height: 204,
signal: abortController.signal,
onThumbnail: (thumbnail, pageNumber) => {
container.appendChild(thumbnail);
},
});
open()
open: (
inputDocument) =>Promise<void>
Opens a document in the PDF viewer.
Parameters
inputDocument
The input document to be opened, either as a File object or a URI string.
Returns
Promise<void>
A promise that resolves when the document is opened.
Example
await viewer.document.open({ uri: 'https://example.com/sample.pdf' });
print()
print: (
options?) =>Promise<void>
Prints the current document.
Parameters
options?
Document print options.
Returns
Promise<void>
A promise that resolves when the print dialog is closed.
Example
await viewer.document.print({ pageNumbers: [1, 2], dpi: 300 });
save()
save: (
options?) =>Promise<Blob>
Saves the current document.
Parameters
options?
Document save options
Returns
Promise<Blob>
A promise that resolves to a Blob representing the saved document.
Example
await viewer.document.save();
updateAnnotation()
updateAnnotation: (
annotation) =>Promise<void>
Updates the specified annotation in the document.
Parameters
annotation
The annotation to be updated.
Returns
Promise<void>
A promise that resolves when the annotation is updated.
Example
await viewer.document.updateAnnotation(annotation);
Methods
addEventListener()
addEventListener<
K>(eventName,callback):void
Adds an event listener for a specified event.
Type Parameters
K
K extends keyof DocumentEventMap
Parameters
eventName
K
The name of the event to listen for.
callback
The callback function to execute when the event is triggered.
Returns
void
Inherited from
getCurrentPageNumber()
getCurrentPageNumber():
number
Gets the current page number.
Returns
number
The current page number.
Example
const currentPage = viewer.document.getCurrentPageNumber();
console.log('Current Page Number:', currentPage);
getPageCount()
getPageCount():
number
Gets the total number of pages in the document.
Returns
number
The total number of pages.
Example
const pageCount = viewer.document.getPageCount();
console.log('Total Pages:', pageCount);
removeEventListener()
removeEventListener<
K>(eventName,callback):void
Removes an event listener for a specified event.
Type Parameters
K
K extends keyof DocumentEventMap
Parameters
eventName
K
The name of the event to stop listening for.
callback
The callback function to remove.
Returns
void