Skip to main content
The document object is an instance accessible from the main MuPDFWebViewer instance as follows:
This assumes you have returned your instance name as webViewer from the initMuPDFWebViewer() promise!

document

The document object has the following methods:

open

Opens a PDF document.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.
Example
Please note: when loading a remote PDF then ensure that you have the correct CORS & CSP settings in place to provide the PDF.CORS (Cross-Origin Resource Sharing) and CSP (Content Security Policy) are both web security mechanisms.
  • CORS is about server-to-server communication from browsers
  • CSP is about what content your own webpage can load and execute
If a remote PDF fails to load in MuPDF WebViewer then it is very possible that this might be related to one of these security mechanisms - ensure to check your console logs for any errors!

download

Downloads the PDF file.

Parameters

object
Optional configuration. If omitted, the original document filename is used and annotations are included.

Returns

Promise
required
A Promise.
Example

getPages

Gets PDF page information.

Parameters

object
Optional configuration. If omitted, all pages are returned.

Returns

Promise<{ pages: PageInfo[]; }>
required
A Promise that resolves to page information.
Example

getPageCount

Gets the total number of pages in the PDF.

Returns

Promise<{ pageCount: number; }>
required
A Promise that resolves to the page count.
Example

close

Closes the currently opened PDF document.

Returns

Promise
required
A Promise.
Example

print

Prints the PDF.

Parameters

object
Optional configuration. If omitted, the whole document is printed.

Returns

Promise<PrintResult>
required
A Promise that resolves to the print result.
Example

rotatePage

Rotates pages.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.
Example

getText

Extracts text from the PDF.

Parameters

object
Optional configuration. If omitted, the whole document is used.

Returns

Promise<{ pageIndex: number; text: string; }[]>
required
A Promise that resolves to extracted text for each page.
Example

export

Exports the PDF. Returns the PDF data in Uint8Array format.

Parameters

object
Optional configuration. If omitted, the document will be exported with annotations.

Returns

Promise<Uint8Array>
required
A Promise that resolves to the exported PDF bytes.
Example

Types Used By document

PageInfo

BBox

PrintResult