Skip to main content

Crate falcon_pdf

Crate falcon_pdf 

Source
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_layers to show others.
Link
A link annotation: the area to click, in display points, and where it goes.
OutlineEntry
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).
SearchOptions
Selection
The text under a drag selection and the rectangles to highlight.

Enums§

LayerNode
One row of the layers tree.
LinkTarget
Where a link in a page goes.
OrderItem
What a walk of /Order found.

Constants§

NEEDS_PASSWORD
The message of the error Document::open returns 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) in text stands as whole words: no letter, digit or underscore touches either end.
layer_tree
The tree for order, in a document of groups groups. Indices past groups are skipped. Nothing when the document has no groups.
open_for_print
Opens the PDF at path as [print] prints it: showing layers (one flag per entry of Document::layers) when given. The file on disk is not changed.
print
Prints the PDF at path (unlocked with password if it has one) through PDFKit’s print operation: the system print panel, then the job named title. layers is 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 a Document stays 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 size display points renders to at scale pixels per point, shrunk so neither side exceeds max_px; never 0.

Type Aliases§

Result