Pure-Ruby PDF library: a byte-level reader, an Arlington-model-driven typed domain model, and a serializer. The PDF object model is sourced directly from the vendored Arlington PDF Model TSVs (the machine-readable definition of ISO 32000-2:2020), so field metadata, version predicates, and validators stay aligned with the spec by data, not by hand-coded mimicry.
Two-direction contract:
-
"PDF file <⇒ Model" — parse PDF bytes into a typed Model and serialize a Model back to PDF bytes. Round-trip is the correctness backbone.
-
"API Builder Input ⇒ Model" —
DocumentandCanvasbuild a typed Model from user intent, which the serializer then writes.
Pdfrb is deliberately scoped to the PDF byte format. Layout concerns
(page templates, flows, line breaking, tables, etc.) live in the
sibling arroolio gem.
Mirrors the layered design of the sibling postscript gem (PS/EPS parser + serializer). Architecture blueprint cross-referenced against HexaPDF.
Installation
gem install pdfrb
Usage (sketch — APIs land across the TODO sequence)
Architecture
| Layer | Owns |
|---|---|
|
PDF bytes → tokens → COS object graph (read direction). |
|
Typed PDF domain model: COS scalars + |
|
Loads vendored TSVs; evaluates |
|
Stream filter pipeline (FlateDecode, LZWDecode, …). |
|
Content-stream operators + Canvas drawing API. |
|
Model → PDF bytes (COS). |
|
Document → file (xref + trailer assembly). |
|
Top-level facade. |
Adding a new PDF type = adding one Model::Type::* subclass that
declares arlington_object "Name". Adding a new content operator =
one subclass + register_as. Adding a new filter = one subclass
register. No switch edits (Open/Closed).
Reference materials
| Path | Role |
|---|---|
|
Sibling gem to mimic for conventions. |
|
Canonical PDF object model (TSV data). |
|
Reference Ruby implementation. |
|
AsciiDoc source of ISO 32000-2. |
|
App Note 002: Associated Files. |
|
App Note 003: Metadata stream locations. |
|
PDF/UA Tech Note 001: ActualText on Figure. |
|
PDF/UA Tech Note 002: Reference elements with links. |
License
BSD-2-Clause. See LICENSE.