Skip to main content

Crate otf_pdf

Crate otf_pdf 

Source
Expand description

A from-scratch toolkit to parse, edit, sign, verify, generate, validate and render PDFs.

This facade is the public API; the otf-pdf-* crates behind it are internal and may change freely. See the API guide for a tour by task, and the embedding guide for threading, limits and errors.

Input is read through the Source trait, so the caller decides where bytes come from; this crate does no I/O of its own.

use otf_pdf::{Document, OpenOptions};

let doc = Document::open(bytes, OpenOptions::default())?;
assert_eq!(doc.page_count()?, 1);
// That file has no xref; the repair is recorded, not hidden.
assert!(!doc.diagnostics().is_empty());

Modules§

content
Content-stream interpretation: run a page through your own Device.

Structs§

Attachment
An embedded file from the /EmbeddedFiles name tree.
AttachmentOptions
Options for Document::add_attachment.
Diagnostic
One repair, with where it happened.
Dict
A dictionary. Keys are kept sorted, so iteration (and anything written from it) is deterministic. A repeated key keeps its last value.
Document
A document opened for reading.
Encryption
Encryption for a full save: always AES-256 (revision 6).
File
A PDF file opened for reading. Objects are parsed on first access and cached; the file itself is never modified.
Header
A located file header.
Info
The document information dictionary (§14.3.3), decoded.
Limits
Limits applied while reading. Every one is enforced; exceeding one is an error (crate::Error::Limit), never a panic or unbounded work.
Name
A name object, without its leading / and with #xx escapes resolved.
ObjId
An indirect object’s identity: object number and generation.
OpenOptions
How to open a file.
OutlineItem
One outline (bookmark) item.
Page
One page, with inherited attributes resolved.
PageText
The text of one page.
PdfString
A string object’s bytes, and whether it was written in hex.
Permissions
What an encrypted document allows a user-password reader to do (ISO 32000-2 Table 22). The owner password allows everything.
Rect
A rectangle [llx lly urx ury], normalized so llx <= urx and lly <= ury.
SanitizeOptions
What Document::sanitize removes. SanitizeOptions::default removes everything that can run or hide data, and keeps links and metadata.
SanitizeReport
How many items of each kind were removed.
SaveOptions
Options for Document::save.
SecurityHandler
A security handler, authenticated and ready to decrypt.
SourceError
A Source failed to serve a read.
Store
Base file plus overlay.
Stream
A stream: its dictionary and its bytes exactly as stored in the file, still encoded and (if the file is encrypted) still encrypted.
TextChar
One character (or /ActualText replacement) as drawn.
TextExtractor
Extracts text from a document. Fonts are loaded once and shared across pages.
TextLine
A line of text.
Version
A PDF version as written in the header, e.g. 1.7.
Word
A word: characters between spaces on one line.

Enums§

Authentication
Which password opened the file.
CryptMethod
How one class of data (strings, streams, embedded files) is encrypted.
DiagnosticKind
What was repaired or tolerated.
Error
Everything that can go wrong in the syntax layer.
HeaderError
Why no header could be read.
LimitKind
Which limit was exceeded.
Object
Any PDF object.
SaveMode
How to save.
Strictness
Whether malformed input may be repaired.
XrefEntry
Where an object lives.

Constants§

HEADER_SEARCH_WINDOW
How far into a file the header is looked for.

Traits§

Budget
A CPU budget hook: work is charged in abstract units (roughly, bytes or objects processed), and the hook stops processing by returning false.
Entropy
Randomness, injected by the host (docs/PLAN.md §2: no ambient I/O). Encryption takes keys, salts and IVs from it; a deterministic source gives byte-identical output.
Sink
Where a saved document is written. Like crate::Source, it keeps the core crates free of ambient I/O: the host decides whether bytes go to memory, a file or a socket.
Source
Random-access bytes a document is read from.

Functions§

decode_text_string
Decodes a text string: UTF-16BE with a BOM, UTF-8 with a BOM (PDF 2.0), otherwise PDFDocEncoding. UTF-16LE with a BOM, which some writers emit, is accepted too. Undecodable units become U+FFFD.
encode_text_string
Encodes a text string: PDFDocEncoding when every character has a byte there, otherwise UTF-16BE with a byte order mark (works in every version).
find_header
Finds the %PDF-M.m header in the first HEADER_SEARCH_WINDOW bytes.
to_bytes
object in PDF syntax, as a byte vector.
write_object
Appends object in PDF syntax. A stream is written as its dictionary followed by stream, its raw bytes and endstream.

Type Aliases§

Result
The syntax layer’s result type.