Document
¶
MuPDF can open many document types (PDF, XPS, CBZ, EPUB, FB2 and a handful of image formats).
- new Document.openDocument(fileName, fileType)¶
Constructor method.
Open the named document.
- Arguments:
fileName – File name to open.
fileType – File type.
- Returns:
Document
.
EXAMPLE
var document = new mupdf.Document.openDocument("my_pdf.pdf", "application/pdf");
Instance methods
- needsPassword()¶
Returns true if a password is required to open a password protected PDF.
- Returns:
Boolean
.
EXAMPLE
var needsPassword = document.needsPassword();
- authenticatePassword(password)¶
Returns a bitfield value against the password authentication result.
- Arguments:
password – The password to attempt authentication with.
- Returns:
Integer
.
Bitfield value
Description
0
Failed
1
No password needed
2
Is User password and is okay
4
Is Owner password and is okay
6
Is both User & Owner password and is okay
EXAMPLE
var auth = document.authenticatePassword("abracadabra");
- hasPermission(permission)¶
Returns true if the document has permission for the supplied permission
String
parameter.- Arguments:
permission –
String
The permission to seek for, e.g. “edit”.
- Returns:
Boolean
.
String
Description
Can print
edit
Can edit
Can copy
annotate
Can annotate
form
Can fill out forms
accessibility
Can copy for accessibility
assemble
Can manage document pages
print-hq
Can print high-quality
EXAMPLE
var canEdit = document.hasPermission("edit");
- getMetaData(key)¶
Return various meta data information. The common keys are:
format
,encryption
,info:ModDate
, andinfo:Title
.- Arguments:
key –
String
.
- Returns:
String
.
EXAMPLE
var format = document.getMetaData("format"); var modificationDate = doc.getMetaData("info:ModDate"); var author = doc.getMetaData("info:Author");
- setMetaData(key, value)¶
Set document meta data information field to a new value.
- Arguments:
key –
String
.value –
String
.
EXAMPLE
document.setMetaData("info:Author", "My Name");
- isReflowable()¶
Returns true if the document is reflowable, such as EPUB, FB2 or XHTML.
- Returns:
Boolean
.
EXAMPLE
var isReflowable = document.isReflowable();
Note
This will always return
false
in the WASM context as there is no HTML/EPUB support in WASM.
- layout(pageWidth, pageHeight, fontSize)¶
Layout a reflowable document (EPUB, FB2, or XHTML) to fit the specified page and font size.
- Arguments:
pageWidth –
Int
.pageHeight –
Int
.fontSize –
Int
.
EXAMPLE
document.layout(300,300,16);
- countPages()¶
Count the number of pages in the document. This may change if you call the layout function with different parameters.
- Returns:
Int
.
EXAMPLE
var numPages = document.countPages();
- loadPage(number)¶
Returns a Page (or PDFPage) object for the given page number. Page number zero (0) is the first page in the document.
- Returns:
Page
orPDFPage
.
EXAMPLE
var page = document.loadPage(0); // loads the 1st page of the document
- loadOutline()¶
Returns an array with the outline (also known as “table of contents” or “bookmarks”). In the array is an object for each heading with the property ‘title’, and a property ‘page’ containing the page number. If the object has a ‘down’ property, it contains an array with all the sub-headings for that entry.
- Returns:
[...]
.
EXAMPLE
var outline = document.loadOutline();
- outlineIterator()¶
Returns an OutlineIterator for the document outline.
- Returns:
OutlineIterator
.
EXAMPLE
var obj = document.outlineIterator();
- resolveLink(uri)¶
Resolve a document internal link URI to a page index.
- Arguments:
uri –
String
.
- Returns:
Integer
.
EXAMPLE
var pageNumber = document.resolveLink(my_link);
- resolveLinkDestination(uri)¶
Resolve a document internal link URI to a link destination.
- Arguments:
uri –
String
.
- Returns:
EXAMPLE
var linkDestination = document.resolveLinkDestination(uri);
- isPDF()¶
Returns true if the document is a PDF document.
- Returns:
Boolean
.
EXAMPLE
var isPDF = document.isPDF();
- asPDF()¶
Returns a pdf version of the document (if possible). PDF documents return the same object. Documents that have an underlying PDF representation return that. Other document types return null.
- Returns:
PDFDocument
.
EXAMPLE
var asPDF = document.asPDF();
- formatLinkURI(linkDestination)¶
Format a document internal link destination object to a URI string suitable for createLink().
- Arguments:
linkDestination – Link destination.
- Returns:
String
.
EXAMPLE
var uri = document.formatLinkURI({chapter:0, page:42, type:"FitV", x:0, y:0, width:100, height:50, zoom:1}); document.createLink([0,0,100,100], uri);