Expand description
The PDF syntax layer: the object model, its exact serialization, the lexer, the object parser and the stream filters (ISO 32000-2 §7.2–7.4).
use laminapdf_syntax::{Object, parse_object};
let obj = parse_object(b"<< /Kids [3 0 R] /Count 1 >>")?;
assert_eq!(obj.as_dict().and_then(|d| d.get_int("Count")), Some(1));
assert_eq!(obj.to_bytes(), b"<< /Kids [3 0 R] /Count 1 >>");This crate is part of Lamina PDF’s pure core: it takes bytes and returns values, and never
touches the file system, network, clocks or threads, so it builds for native, WebAssembly
and mobile targets alike. Every parse path returns Result; no input panics. Recursion
only happens in the object parser, which is depth-limited (Limits::max_nesting_depth).
Objectand friends: the object model and its byte-exact serialization.parse_object/Parser: the tolerant object parser (indirect objects and streams, with anendstreamscan when/Lengthis wrong).Lexer/Token: the tokenizer the parser and the cross-reference reader share.filters: Flate encode/decode withinLimits, and PNG predictors.crypt: standard security handler decryption (read only): password authentication for R2–R6 and RC4 / AES-128 / AES-256 string and stream decryption.ErrorKind,PositionandLocation: the shared parts of the error contract (ADR 0026): kinds and tagged positions;ErrorCodeandWarningCode, every code’s kind, hint anddocsUrl(generated fromfixtures/codes.json); and, with thejsonfeature,Diagnostic, the §1 object every boundary serialises.Limits: the resource limits of ADR 0003, shared by every layer that reads input.Rotation: a rotation by a multiple of 90°, read from/Rotatevalues and shared by the page model and the renderers.text: text strings (PDFDocEncoding, UTF-16BE, UTF-8) and thePDFDocEncodingtable.
The file structure (cross-reference tables, object streams, repair, the page tree) and the
writer live one layer up, in laminapdf-cos.
Modules§
- crypt
- Standard security handler decryption (ISO 32000-2 §7.6; ISO 32000-1 §7.6.3 for R2–R4): password authentication for revisions 2–6 and string/stream decryption with RC4, AES-128-CBC and AES-256-CBC.
- filters
- Stream filters: Flate (via
miniz_oxide) and PNG predictors (ISO 32000-1 §7.4.4). - text
- Text strings (ISO 32000-2 §7.9.2.2):
PDFDocEncoding, UTF-16BE with a byte-order mark, and (PDF 2.0) UTF-8 with a byte-order mark.
Structs§
- Budget
- How much work one step of a job may do, in work units, not time (ADR 0028 §4): the core has no clock, so the same budget gives the same step boundaries everywhere. One unit is one cheap, indivisible piece of work; each job documents its weights. Edges measure time between steps and adapt the next budget.
- Cancel
Token - A cancel flag shared by the jobs and calls it is passed to (ADR 0028 §5). Cloning shares the flag: cancel one clone and every holder sees it.
- Decode
Budget - The decoding budget of one top-level call:
Limits::max_decoded_totalbytes, spent by every filter stage of every stream the call decodes. - Diagnostic
- One error or warning as the ADR 0026 §1 object: what the façade’s
ErrorandWarningserialise to, what the WASM bindings throw, as a record of strings and numbers an edge maps one-to-one (theUniFFIDiagnosticrecord, the TSLaminaPdfErrorfields; ADR 0028 F9). Serialises with camelCase keys, optional keys omitted (nevernull). - Dict
- An insertion-ordered dictionary. Lookups are linear, which is faster than hashing for the handful of keys real PDF dictionaries carry.
- Indirect
Object - The result of
Parser::indirect_object. - Lexer
- A cursor over PDF bytes that yields
Tokens. - Limits
- Resource limits for reading untrusted PDF input (ADR 0003 §3).
- Location
- The
locationof a serialized diagnostic (ADR 0026 §1.1): each field names one kind of position, and all of them are lamina-made values, never document text. - Name
- A PDF name, stored as its decoded bytes without the leading
/. - ObjRef
- A reference to an indirect object:
num gen R. - Parser
- A parser over PDF bytes, positioned at a byte offset.
- PdfString
- A PDF string: raw bytes plus the syntax it was written in.
- Stream
- A stream: its dictionary plus the raw (still encoded) bytes between
streamandendstream. - Stream
Head - A stream’s header and dictionary, before its data is read (
Parser::indirect_head).
Enums§
- Error
- Everything that can go wrong while lexing, parsing or decoding PDF syntax.
- Error
Code - Every error code lamina’s Rust crates and its WASM binding raise (the codes only
@laminapdf/sdkraises are not here), incodes.jsonorder. - Error
Kind - What kind of failure a code is: what the caller can do about it (ADR 0026 §2).
- Indirect
Head - What
Parser::indirect_headread. - Limit
- Which hard limit was exceeded (the
limitofError::LimitExceeded). - Object
- A PDF object.
- Phase
- What a job is doing (ADR 0028 §3).
- Position
- Where an error was found, tagged so that a number has one meaning (ADR 0026 §1.1).
- Rotation
- A rotation by a multiple of 90°, clockwise when displayed: a page’s
/Rotate(§7.7.3.3), or a view rotation added to it. - Step
- What a step returns: progress, or the job’s result (Rust-only; edges expose a concrete record per job, ADR 0028 F3).
- String
Format - How a string was (or should be) written:
(literal)or<hex>. - Token
- One lexical token. Keywords borrow from the input; decoded values are owned.
- Warning
Code - Every warning code, in
codes.jsonorder.
Constants§
- DOCS_
URL_ BASE - The base of every
docsUrl(ADR 0026 §6):DOCS_URL_BASE+ code +DOCS_URL_SUFFIX. - DOCS_
URL_ SUFFIX - The suffix of every
docsUrl(ADR 0026 §6).
Functions§
- did_
you_ mean - The known names within two edits of
given, closest first; names at the same distance in code-point order. Edits count chars, after lowercasing ASCII letters only (fixtures/did-you-mean.jsonpins the rule for both languages). - endstream_
at - Whether
endstreamfollowsendafter optional white-space: the check that a stream’s declared/Lengthis right. Setsreached_endwhen the answer depends on bytes past the end ofdata. - find
- Finds the first occurrence of
needleinhayat or after byte offsetfrom, returning its offset. Used to recover stream extents (endstream) and, inlaminapdf-cos, to locate file-structure keywords.Nonewhenfromis past the end orneedleis absent. - format_
real - Formats a real: never an exponent, at most 6 fractional digits, trailing zeros and a
trailing
.trimmed,-0becomes0. Non-finite values (which PDF cannot express) are written as0. - is_
delimiter - PDF delimiter characters (Table 2).
- is_
regular - Neither white-space nor delimiter.
- is_
whitespace - PDF white-space characters (Table 1).
- parse_
object - Parses a single direct object from
inputwith the defaultLimits. Trailing white-space and comments are allowed; anything else after the object is an error. - parse_
object_ with parse_objectwith explicitlimits.- stream_
data_ end - The end of stream data that starts at
fromwhen itsendstreamkeyword is atidx: the EOL before the keyword (CRLF, LF or CR) is not data. Reads onlydata[idx - 2..idx].
Type Aliases§
- Result
- Shorthand for
Result<T, laminapdf_syntax::Error>.