NativeElixirPdfUtilities.Merge (native_elixir_pdf_utilities v0.2.0)

View Source

Minimal PDF utilities for merging PDF binaries using the tokenizer.

Notes and constraints:

  • Emits a classic PDF 1.7 header and builds a fresh xref + trailer.
  • Copies all objects from inputs, renumbering to avoid collisions.
  • Adjusts indirect references (n g R) to the new numbering.
  • Collects Page objects and builds a new Catalog + Pages tree that references them.
  • Leaves stream bytes untouched and preserves declared /Length (direct or indirect ref), only renumbering indirect references as needed.
  • Does not decode filters or resolve xref streams; expects classic PDFs tokenizable by the tokenizer.

The merger is conservative and pragmatic, targeting structural correctness for common PDFs.

Summary

Types

Mapping from original object id to new object id.

Object record captured while indexing inputs.

Byte-offset table for xref: object id -> {byte_offset, generation}.

A single token as produced by NativeElixirPdfUtilities.Tokenizer.

A list of PDF tokens.

Functions

Merge a list of PDF binaries into a single PDF binary.

Types

id_map()

@type id_map() :: %{optional(integer()) => integer()}

Mapping from original object id to new object id.

obj_rec()

@type obj_rec() :: %{obj: integer(), gen: integer(), tokens: tokens()}

Object record captured while indexing inputs.

offsets_map()

@type offsets_map() :: %{
  optional(integer()) => {non_neg_integer(), non_neg_integer()}
}

Byte-offset table for xref: object id -> {byte_offset, generation}.

pdf_bin()

@type pdf_bin() :: binary()

token()

A single token as produced by NativeElixirPdfUtilities.Tokenizer.

tokens()

@type tokens() :: [token()]

A list of PDF tokens.

Functions

merge(bins)

@spec merge([pdf_bin()]) :: {:ok, pdf_bin()}

Merge a list of PDF binaries into a single PDF binary.

This is a best-effort merger for classic PDFs. It renumbers all objects of each input, collects Page objects, and emits a new Catalog/Pages tree that references all pages.