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. The matrix 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. If alpha is true, the page will be drawn on a transparent background, otherwise white. If showExtras is true then the operation will include any page annotations and/or widgets.

Arguments:
  • matrix[a,b,c,d,e,f]. The transform matrix.

  • colorspaceColorSpace.

  • alphaBoolean.

  • showExtrasBoolean.

Returns:

Pixmap.

Note

In MuPDF WASM alpha & showExtras default to true unless otherwise specified. In mutool run alpha defaults to false and showExtras 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:
  • showExtrasBoolean.

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:
  • optionsString.

Returns:

StructuredText.

EXAMPLE

var sText = page.toStructuredText("preserve-whitespace");

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:
  • needleString.

  • max_hitsInteger 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.

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.

Delete the link from the page.

Arguments:

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 extends Page this method will return false. It is only if we actually have an instance of a PDFPage when this method is overridden to return true.