document
object is an instance accessible from the main mupdfwv.MuPDFWebViewer instance as follows:
This assumes you have returned your instance name as
mupdf
from the initMuPDFWebViewer() promise!document
Thedocument
object has the following methods:
open
open(config: { url: string, filename: string })
Opens a PDF document.
- Arguments:
- config – (required) The configuration object.
-
Arguments:
- url – (required) File path to open.
- filename – (required) The file name to use for the file.
-
Returns:
Promise
.
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
close
close()
Closes the currently opened PDF document.
- Returns:
Promise
.
download
download(config?: { fileName?: string, includeAnnotations?: boolean })
Downloads the PDF file.
- Arguments:
- config – (optional) The configuration object. If not set the original document filename is used with any annotations included.
- Arguments:
- fileName – (optional) Name of the file to download.
- includeAnnotations – (optional) Default
true
. Whether to include annotations.
- Returns:
Promise
.
export
export(config?: { includeAnnotations?: boolean })
Exports the PDF. Returns the PDF data in Uint8Array
format.
- Arguments:
- config – (optional) The configuration object. If not set the document will be exported with annotations.
- Arguments:
- includeAnnotations – (optional) Default
true
. Whether to include annotations.
- includeAnnotations – (optional) Default
- Returns:
Promise<Uint8Array<ArrayBufferLike>>
.
getPages
getPages(config?: { pageRange?: string })
Gets PDF page information.
- Arguments:
- config – (optional) The configuration object. If not set then all pages are returned.
- Arguments:
- pageRange – (optional) Default: “all”. Page index range (e.g., “0-5, 7, 9-12”, “all”).
Page references are zero-indexed.
- Returns:
Promise<{ pages: mupdfwv.PageInfo[]; }>
.
getPageCount
getPageCount()
Gets the total number of pages in the PDF.
- Returns:
Promise<{ pageCount: number; }
.
print(config?: { pageRange: string })
Prints the PDF.
- Arguments:
- config – (optional) The configuration object. If not set then the whole document will be printed.
- Arguments:
- pageRange – (required) Page index range (e.g., “0-5, 7, 9-12”, “all”).
Page references are zero-indexed.
- Returns:
Promise<mupdfwv.PrintResult>
.
rotatePage
rotatePage(config: { pageRange: string, degree: mupdf.refs.degree })
Rotates pages.
- Arguments:
- config – (required) The configuration object.
- Arguments:
- pageRange – (required) Page index range (e.g., “0-5, 7, 9-12”, “all”).
Page references are zero-indexed.
- Returns:
Promise
.
getText
getText(config?: { pageRange?: string })
Extracts text from the PDF.
- Arguments:
- config – (optional) The configuration object. If not set then the whole document will be used.
- Arguments:
- pageRange – (optional) Default: “all”. Page index range (e.g., “0-5, 7, 9-12”, “all”).
- Returns:
Promise<{ pageIndex: number; text: string; }[]>
.