pub struct Document {
pub root: Option<ObjectId>,
pub info: Option<ObjectId>,
pub encryption: Option<EncryptionState>,
pub xref_stream: bool,
pub object_stream: bool,
pub prev_xref_offset: Option<u64>,
pub min_size: Option<u32>,
pub xref_only_ids: Option<Vec<u32>>,
/* private fields */
}Expand description
The whole PDF document — an append-only list of indirect objects plus a /Root reference (and optional /Info reference) for the trailer dictionary.
Fields§
§root: Option<ObjectId>§info: Option<ObjectId>Optional document-level information dictionary. When set, the
reference is written into the trailer as /Info <n> <gen> R —
PDF readers surface the dictionary’s /Title, /Author, etc.
keys as the document’s metadata. ISO 32000-1 §14.3.3 also
allows arbitrary additional keys, used by the round-2 writer
to round-trip custom scene metadata.
encryption: Option<EncryptionState>Optional encryption state. When set, every string and stream
payload in the body is encrypted via the standard handler
(Algorithms 1 + 4/5 / 8/9 / etc.) and the trailer carries
/Encrypt <n> 0 R + a matching /ID array. The dictionary
itself (the Encrypt object) is not encrypted — see
ISO 32000-1 §7.6.1.
xref_stream: boolWhen true, Self::write_to emits a PDF 1.5+ cross-reference
stream (/Type /XRef, ISO 32000-1 §7.5.8) instead of the
classical xref-keyword table. The trailer dict is folded into
the stream’s own dictionary (per §7.5.8.2), so the file no
longer carries a separate trailer << ... >> block.
The xref stream uses /W [1 4 2] — one byte for the entry
type, four bytes for the offset (or compressed-stream id), two
bytes for the generation (or in-stream index). The body is
flate-compressed with the PNG-Up /Predictor 12 so the
reader’s predictor reversal is exercised end-to-end.
object_stream: boolWhen true (and Self::xref_stream is also true),
Self::write_to packs every compressible indirect object
(non-stream, non-Encrypt, non-Catalog-when-flagged) into one
/Type /ObjStm container per ISO 32000-1 §7.5.7. The xref
stream’s type-2 entries point at the container; the round-7
reader’s crate::reader::DocumentReader::resolve follows
them. Implies a PDF 1.5+ header (already implied by
Self::xref_stream).
Stream objects (content streams, image XObjects, the xref stream itself, the encryption-metadata stream, etc.) cannot live inside an ObjStm (§7.5.7) and remain at their own byte offsets. The Encrypt indirect object (when set) is excluded because §7.6.1 forbids it from being compressed.
prev_xref_offset: Option<u64>Optional pointer at a previous cross-reference section’s byte
offset. When Some(off), the trailer dict (or, with
Self::xref_stream, the xref-stream dict) carries
/Prev <off> per ISO 32000-1 §7.5.6 — the marker that lets a
reader walk a chain of incremental updates. Set by
crate::write_pdf_incremental_update on the new revision’s
document; unused for one-shot writes.
min_size: Option<u32>When emitting an incremental update, the reader’s view of
/Size must be at least the original revision’s /Size —
this honours that minimum even when the new revision adds
only one or two indirect objects past the old maximum.
xref_only_ids: Option<Vec<u32>>When emitting an incremental update, the body section is
appended to a previous file’s bytes. The xref subsection
header(s) the writer emits must list only the changed slots
and skip the unchanged ones. When set, the xref emitter (both
classical and stream forms) groups slots into contiguous
subsections covering only these ids (and id 0 for the
free-list head); when None the writer emits one subsection
covering [0, max_id].
Implementations§
Source§impl Document
impl Document
pub fn new() -> Self
Sourcepub fn set_next_id(&mut self, next_id: u32)
pub fn set_next_id(&mut self, next_id: u32)
Pre-seed the next-id allocator past max_id. Used by the
incremental-update writer to make new objects pick up after
the previous revision’s maximum id.
Sourcepub fn next_id(&self) -> u32
pub fn next_id(&self) -> u32
The next id Self::allocate_id will hand out. Useful for
the incremental-update writer to know where the new revision’s
id range starts.
Sourcepub fn allocate_id(&mut self) -> ObjectId
pub fn allocate_id(&mut self) -> ObjectId
Reserve a fresh id without committing the object body. Useful when two objects need to reference each other (page → resources, resources → page); allocate both ids first, then fill them in.
Sourcepub fn add_object(&mut self, id: ObjectId, object: Object)
pub fn add_object(&mut self, id: ObjectId, object: Object)
Add an object that already has an id (one obtained via
Self::allocate_id).
Sourcepub fn add(&mut self, object: Object) -> ObjectId
pub fn add(&mut self, object: Object) -> ObjectId
Allocate-and-add in one step. Returns the assigned id.
Sourcepub fn object_count(&self) -> usize
pub fn object_count(&self) -> usize
Number of indirect objects committed so far.
Sourcepub fn object_mut(&mut self, id: ObjectId) -> Option<&mut Object>
pub fn object_mut(&mut self, id: ObjectId) -> Option<&mut Object>
Borrow the object body of the indirect object at id for
mutation. Used by writer code paths that need to extend the
catalog dictionary after crate::page::build_pages has
returned (e.g. to attach /Metadata <ref> per ISO 32000-1
§14.3.2). Returns None when id was never committed.