PdfEx.Document (pdf_ex v0.1.0)

Copy Markdown View Source

The immutable in-memory representation of an opened PDF.

Holds the original source bytes, the parsed xref_map and trailer, the pending dirty_objects overlay (edits, applied at serialize time), and the captured revision/xref style needed for byte-exact incremental updates. Lazy projections (glyphs, uid_index) are derived on demand and reset whenever the dirty overlay changes (see commit_dirty/2). Treated as opaque by callers — construct it via PdfEx.open/1, never by hand.

Summary

Functions

Installs a new dirty overlay and drops the derived projections (glyphs, uid_index) — any object change can invalidate them.

Types

dirty_entry()

@type dirty_entry() :: {:update, any()} | :free

generation()

@type generation() :: non_neg_integer()

object_id()

@type object_id() :: pos_integer()

offset_entry()

@type offset_entry() ::
  {:resolved, non_neg_integer()}
  | {:compressed, object_id(), non_neg_integer()}
  | :free

ref_key()

@type ref_key() :: {object_id(), generation()}

t()

@type t() :: %PdfEx.Document{
  dirty_objects: %{required(ref_key()) => dirty_entry()},
  glyphs: %{required(ref_key()) => [PdfEx.Model.Glyph.t()]} | nil,
  object_cache: %{required(ref_key()) => any()},
  revision_xref_offset: non_neg_integer() | nil,
  source: binary(),
  trailer: map(),
  uid_index:
    %{
      required(binary()) =>
        {:glyph, ref_key(), non_neg_integer(), non_neg_integer()}
    }
    | nil,
  xref_map: %{required(ref_key()) => offset_entry()},
  xref_style: :classic | :stream | nil
}

Functions

commit_dirty(doc, dirty)

@spec commit_dirty(t(), %{required(ref_key()) => dirty_entry()}) :: t()

Installs a new dirty overlay and drops the derived projections (glyphs, uid_index) — any object change can invalidate them.

Every dirty-object write must go through here; updating dirty_objects with plain struct-update syntax leaves stale projections behind.