PdfEx.Filter (pdf_ex v0.1.0)

Copy Markdown View Source

Single entry point for stream filter dispatch.

Normalizes every legal /Filter form — absent, a single name, or an array of names (with the /F abbreviation), plus the matching /DecodeParms///DP forms (dict, array of dicts/nulls, absent) — and applies the decode chain in order.

Two variants serve the two caller postures:

  • decode/1 — strict: unsupported filters and decode failures are errors. For structural streams (xref streams, object streams) whose bytes are useless undecoded.
  • decode_lenient/1 — best-effort: any failure returns the raw bytes unchanged. For content extraction, where partial output beats none.

Indirect (%PdfEx.COS.Reference{}) /DecodeParms are treated as "no parameters" rather than resolved (rare in practice; resolving would require threading the document through every decode call).

Summary

Functions

Strictly decodes a stream's filter chain. Unsupported filters or decode failures return {:error, reason}.

Best-effort decode: returns the decoded bytes, or the raw bytes unchanged on any failure.

Types

error_reason()

@type error_reason() :: atom() | tuple()

Functions

decode(stream)

@spec decode(PdfEx.COS.Stream.t()) :: {:ok, binary()} | {:error, error_reason()}

Strictly decodes a stream's filter chain. Unsupported filters or decode failures return {:error, reason}.

decode_lenient(stream)

@spec decode_lenient(PdfEx.COS.Stream.t()) :: binary()

Best-effort decode: returns the decoded bytes, or the raw bytes unchanged on any failure.