Skip to main content

Document

Struct Document 

Source
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: bool

When 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: bool

When 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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

pub fn add_object(&mut self, id: ObjectId, object: Object)

Add an object that already has an id (one obtained via Self::allocate_id).

Source

pub fn add(&mut self, object: Object) -> ObjectId

Allocate-and-add in one step. Returns the assigned id.

Source

pub fn object_count(&self) -> usize

Number of indirect objects committed so far.

Source

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.

Source

pub fn write_to(&self, out: &mut Vec<u8>) -> Result<(), PdfError>

Walk this document into the on-wire layout: header + body + xref + trailer + startxref. Bytes for sub-objects are emitted in insertion order.

Trait Implementations§

Source§

impl Default for Document

Source§

fn default() -> Document

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V