View Source Pdf.Reader.Trailer (ExPDF v1.0.1)
Locates the startxref byte offset in a PDF binary and parses the
trailer dictionary at a given xref section offset.
PDF spec references
- § 7.5.5 — File Trailer
- § 7.5.4 — Cross-Reference Table
Summary
Functions
Scans binary in reverse for %%EOF, then reads the startxref offset
on the line immediately before it.
Parses the xref section and trailer dictionary at offset within binary.
Types
@type t() :: %Pdf.Reader.Trailer{ dict: map(), encrypt: term(), id: [{:hex_string, binary()} | {:string, binary()} | binary()] | nil, info: Pdf.Reader.Document.ref() | nil, prev: non_neg_integer() | nil, root: Pdf.Reader.Document.ref() | nil, size: pos_integer() | nil }
Functions
@spec locate_startxref(binary()) :: {:ok, non_neg_integer()} | {:error, :malformed}
Scans binary in reverse for %%EOF, then reads the startxref offset
on the line immediately before it.
Returns {:ok, offset} or {:error, :malformed}.
Per PDF spec § 7.5.5: the file ends with %%EOF. The line above that is
the byte offset to the xref section. The line above that is the keyword
startxref.
@spec parse(binary(), non_neg_integer()) :: {:ok, t()} | {:error, :malformed}
Parses the xref section and trailer dictionary at offset within binary.
Seeks forward from offset to the trailer keyword, then parses the
dictionary that follows. Populates a %Pdf.Reader.Trailer{} struct.
Returns {:ok, %Pdf.Reader.Trailer{}} or {:error, :malformed}.