Document API
The 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
The document
object has the following methods:
open
open(config: { url: string, filename: string })
Opens a PDF document.
- Arguments:
- config – (required) The configuration object.
Config object:
-
Arguments:
- url – (required) File path to open.
- filename – (required) The file name to use for the file.
-
Returns:
Promise
.
Example
close
close()
Closes the currently opened PDF document.
- Returns:
Promise
.
Example
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.
Config object:
- Arguments:
- fileName – (optional) Name of the file to download.
- includeAnnotations – (optional) Default
true
. Whether to include annotations.
- Returns:
Promise
.
Example
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.
Config object:
- Arguments:
- includeAnnotations – (optional) Default
true
. Whether to include annotations.
- includeAnnotations – (optional) Default
- Returns:
Promise<Uint8Array<ArrayBufferLike>>
.
Example
getPages
getPages(config?: { pageRange?: string })
Gets PDF page information.
- Arguments:
- config – (optional) The configuration object. If not set then all pages are returned.
Config object:
- 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[]; }>
.
Example
getPageCount
getPageCount()
Gets the total number of pages in the PDF.
- Returns:
Promise<{ pageCount: number; }
.
Example
print(config?: { pageRange: string })
Prints the PDF.
- Arguments:
- config – (optional) The configuration object. If not set then the whole document will be printed.
Config object:
- Arguments:
- pageRange – (required) Page index range (e.g., “0-5, 7, 9-12”, “all”).
Page references are zero-indexed.
- Returns:
Promise<mupdfwv.PrintResult>
.
Example
rotatePage
rotatePage(config: { pageRange: string, degree: mupdf.refs.degree })
Rotates pages.
- Arguments:
- config – (required) The configuration object.
Config object:
- Arguments:
- pageRange – (required) Page index range (e.g., “0-5, 7, 9-12”, “all”).
Page references are zero-indexed.
- Returns:
Promise
.
Example
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.
Config object:
- Arguments:
- pageRange – (optional) Default: “all”. Page index range (e.g., “0-5, 7, 9-12”, “all”).
- Returns:
Promise<{ pageIndex: number; text: string; }[]>
.
Example