Expand description
PDF documents for falcon’s viewer, through the operating system’s own
PDF engine: PDFKit on macOS. The one third-party PDF library, lopdf (MIT),
only reads a file’s structure so that layers can be switched (ocg).
Document opens a file and hands out what a reader needs: page
sizes, pages or parts of them rendered to RGBA pixels at any scale, each page’s text,
search hits, the text and rectangles of a drag selection, and the table
of contents.
A Document may be opened and used on any thread, but only on the
thread that opened it (it is not Send). The viewer opens it on a
worker thread so a slow or not-yet-downloaded file never blocks the UI.
All coordinates in this API are display points: PDF points (1/72
inch) with the origin at the top-left of the page as shown, after the
page’s own rotation. The private geom module converts to and from
PDFKit’s page space (origin bottom-left, unrotated).
All Objective-C interop sits in the private mac module.
Structs§
- Attachment
- A file embedded in the document, as pdf.js’s attachments list shows them: from the catalog’s EmbeddedFiles name tree, then the pages’ file attachment annotations.
- Bitmap
- An RGBA picture, 8 bits per channel, rows top to bottom, opaque.
- Document
- An open PDF file. Usable only on the thread that opened it.
- Error
- Why a document could not be opened or read.
- Hit
- Where a search matched: one page and one rectangle per line of the match.
- Info
- A document’s metadata, for a Document Properties dialog. Dates are seconds since 1970.
- Layer
- An optional content group (“layer”), as pdf.js’s layers list shows
them, with whether the document’s default configuration shows it. Use
Document::set_layersto show others. - Link
- A link annotation: the area to click, in display points, and where it goes.
- Outline
Entry - One entry of the table of contents, flattened in reading order.
- Rect
- A rectangle in display points (origin top-left of the page as shown).
- Search
Options - Selection
- The text under a drag selection and the rectangles to highlight.
Enums§
- Layer
Node - One row of the layers tree.
- Link
Target - Where a link in a page goes.
- Order
Item - What a walk of
/Orderfound.
Constants§
- NEEDS_
PASSWORD - The message of the error
Document::openreturns for a PDF that needs a password, and of the one for a password that doesn’t open it. - WRONG_
PASSWORD
Functions§
- is_
whole_ word - Whether the match
start..start + len(UTF-16 units, as PDFKit counts) intextstands as whole words: no letter, digit or underscore touches either end. - layer_
tree - The tree for
order, in a document ofgroupsgroups. Indices pastgroupsare skipped. Nothing when the document has no groups. - open_
for_ print - Opens the PDF at
pathas [print] prints it: showinglayers(one flag per entry ofDocument::layers) when given. The file on disk is not changed. - Prints the PDF at
path(unlocked withpasswordif it has one) through PDFKit’s print operation: the system print panel, then the job namedtitle.layersis the reader’s choice of layers, if it differs from the document’s default; the job prints what that shows. Must run on the main thread, which it blocks while the panel is up, and opens the file again there, since aDocumentstays on the thread that opened it. Returns whether it printed (false if cancelled). Fails off the main thread, for an unreadable file, when the layers can’t be switched, or when the PDF forbids printing. - render_
size - The pixel size a page of
sizedisplay points renders to atscalepixels per point, shrunk so neither side exceedsmax_px; never 0.