Page
¶
The base class for a PDF Page.
Instance methods
- getBounds()¶
Returns a rectangle containing the page dimensions.
- Returns:
[ulx,uly,lrx,lry]
.
EXAMPLE
var rect = page.getBounds();
- run(device, matrix)¶
Calls device functions for all the contents on the page, using the specified transform matrix. The
device
can be one of the built-in devices or a JavaScript object with methods for the device calls. Thematrix
maps from user space points to device space pixels.- Arguments:
device – The device object.
matrix –
[a,b,c,d,e,f]
. The transform matrix.
EXAMPLE
page.run(obj, mupdf.Matrix.identity);
- runPageContents(device, matrix)¶
This is the same as the run method above but it only considers the page itself and omits annotations and widgets.
- Arguments:
device – The device object.
matrix –
[a,b,c,d,e,f]
. The transform matrix.
EXAMPLE
page.runPageContents(obj, mupdf.Matrix.identity);
- runPageAnnots(device, matrix)¶
This is the same as the run method above but it only considers the page annotations.
- Arguments:
device – The device object.
matrix –
[a,b,c,d,e,f]
. The transform matrix.
EXAMPLE
page.runPageAnnots(obj, mupdf.Matrix.identity);
- runPageWidgets(device, matrix)¶
This is the same as the run method above but it only considers the page widgets.
- Arguments:
device – The device object.
matrix –
[a,b,c,d,e,f]
. The transform matrix.
EXAMPLE
page.runPageWidgets(obj, mupdf.Matrix.identity);
- toPixmap(matrix, colorspace, alpha, showExtras)¶
Render the page into a Pixmap, using the specified transform matrix and
colorspace
. Ifalpha
is true, the page will be drawn on a transparent background, otherwise white. IfshowExtras
is true then the operation will include any page annotations and/or widgets.- Arguments:
matrix –
[a,b,c,d,e,f]
. The transform matrix.colorspace –
ColorSpace
.alpha –
Boolean
.showExtras –
Boolean
.
- Returns:
Pixmap
.
Note
In MuPDF WASM
alpha
&showExtras
default to true unless otherwise specified. In mutool runalpha
defaults to false andshowExtras
defaults to true unless otherwise specified.EXAMPLE
var pixmap = page.toPixmap(mupdf.Matrix.identity, mupdf.ColorSpace.DeviceRGB, true, true);
- toDisplayList(showExtras)¶
Record the contents on the page into a DisplayList. If
showExtras
is true then the operation will include any page annotations and/or widgets.- Arguments:
showExtras –
Boolean
.
- Returns:
DisplayList
.
Note
In both MuPDF WASM and mutool run
showExtras
defaults to true unless otherwise specified.EXAMPLE
var displayList = page.toDisplayList(true);
- toStructuredText(options)¶
Extract the text on the page into a
StructuredText
object. The options argument is a comma separated list of flags: “preserve-ligatures”, “preserve-whitespace”, “preserve-spans”, “preserve-images”, “inhibit-spaces”, “dehyphenate”, “structured”, “use-cid-for-unknown-unicode”, and “ignore-actualtext”.- Arguments:
options –
String
.
- Returns:
StructuredText
.
EXAMPLE
var sText = page.toStructuredText("preserve-whitespace");
- search(needle, max_hits)¶
Search the page text for all instances of the
needle
value, and return an array of search hits. Each search hit is an array of rectangles corresponding to all characters in the search hit.- Arguments:
needle –
String
.max_hits –
Integer
Defaults to 500 unless otherwise specified.
- Returns:
[...]
.
EXAMPLE
var results = page.search("my search phrase");
Note
The numbers are
[ulx, uly, urx, ury, llx, lly, lrx, lry]
for each rectangle against each result. These type of rectangles are know as “Quads” or “QuadPoints” in the PDF specification.
- getLinks()¶
Return an array of all the links on the page. Each link is an object with a ‘bounds’ property, and either a ‘page’ or ‘uri’ property, depending on whether it’s an internal or external link. See: Link.
- Returns:
[...]
.
var links = page.getLinks(); var link = links[0]; var linkDestination = doc.resolveLink(link)
Note
If there are no links then an empty array is returned.
- createLink(rect, destinationUri)¶
Create a new link within the rectangle on the page, linking to the destination URI string.
EXAMPLE
var link = page.createLink([0,0,100,100], "https://example.com");
- deleteLink(link)¶
Delete the link from the page.
- Arguments:
link – Link.
EXAMPLE
page.deleteLink(link_obj);
- getLabel()¶
Returns the page number as a string using the numbering scheme of the document.
- Returns:
String
.
EXAMPLE
var label = page.getLabel();
- isPDF()¶
Returns true if the page is from a PDF document.
- Returns:
Boolean
.
EXAMPLE
var isPDF = page.isPDF();
Note
As
PDFPage
extendsPage
this method will return false. It is only if we actually have an instance of aPDFPage
when this method is overridden to return true.