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§
Structs§
- Attachment
- An embedded file from the
/EmbeddedFilesname tree. - Attachment
Options - 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#xxescapes resolved. - ObjId
- An indirect object’s identity: object number and generation.
- Open
Options - How to open a file.
- Outline
Item - One outline (bookmark) item.
- Page
- One page, with inherited attributes resolved.
- Page
Text - 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 sollx <= urxandlly <= ury. - Sanitize
Options - What
Document::sanitizeremoves.SanitizeOptions::defaultremoves everything that can run or hide data, and keeps links and metadata. - Sanitize
Report - How many items of each kind were removed.
- Save
Options - Options for
Document::save. - Security
Handler - A security handler, authenticated and ready to decrypt.
- Source
Error - A
Sourcefailed 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.
- Text
Char - One character (or
/ActualTextreplacement) as drawn. - Text
Extractor - Extracts text from a document. Fonts are loaded once and shared across pages.
- Text
Line - 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.
- Crypt
Method - How one class of data (strings, streams, embedded files) is encrypted.
- Diagnostic
Kind - What was repaired or tolerated.
- Error
- Everything that can go wrong in the syntax layer.
- Header
Error - Why no header could be read.
- Limit
Kind - Which limit was exceeded.
- Object
- Any PDF object.
- Save
Mode - How to save.
- Strictness
- Whether malformed input may be repaired.
- Xref
Entry - 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.mheader in the firstHEADER_SEARCH_WINDOWbytes. - to_
bytes objectin PDF syntax, as a byte vector.- write_
object - Appends
objectin PDF syntax. A stream is written as its dictionary followed bystream, its raw bytes andendstream.
Type Aliases§
- Result
- The syntax layer’s result type.