NativeElixirPdfUtilities.Pdf.Reader (native_elixir_pdf_utilities v0.6.0)

View Source

Strict, native PDF object reader shared by PDF utilities.

The reader resolves direct and compressed objects, validates the final xref pointer, decodes the standard non-encryption stream filters, and walks the page tree with inherited resources. It intentionally does not decrypt PDFs.

Summary

Functions

Resolves an indirect stream and decodes its declared filters.

Resolves a dictionary value, returning an error when it is not a dictionary.

Returns a dictionary key after resolving the dictionary itself.

Parses a PDF binary into a resolver document.

Resolves an indirect value in a parsed document.

Types

document()

@type document() :: %{
  :objects => %{optional(ref()) => object()},
  optional(atom()) => term()
}

error_reason()

@type error_reason() ::
  :encrypted_pdf
  | :invalid_pdf_input
  | :unsupported_pdf_feature
  | :resource_limit_exceeded

object()

@type object() :: %{
  value: value(),
  stream: binary() | nil,
  offset: non_neg_integer() | nil,
  tokens: [NativeElixirPdfUtilities.Tokenizer.token()]
}

page()

@type page() :: %{
  ref: ref(),
  resources: value() | nil,
  rotate: number() | nil,
  media_box: [number()] | nil
}

ref()

@type ref() :: {non_neg_integer(), non_neg_integer()}

value()

@type value() ::
  nil
  | boolean()
  | integer()
  | float()
  | {:name, binary()}
  | {:string, binary()}
  | {:hex, binary()}
  | {:ref, ref()}
  | [value()]
  | %{optional(binary()) => value()}

xref_entry()

@type xref_entry() ::
  {:free, non_neg_integer(), non_neg_integer()}
  | {:uncompressed, non_neg_integer(), non_neg_integer()}
  | {:compressed, pos_integer(), non_neg_integer()}

Functions

decoded_stream(document, value)

@spec decoded_stream(document(), value()) ::
  {:ok, binary()}
  | {:error,
     {error_reason(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Resolves an indirect stream and decodes its declared filters.

dictionary(document, value)

@spec dictionary(document(), value()) ::
  {:ok, map()}
  | {:error,
     {error_reason(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Resolves a dictionary value, returning an error when it is not a dictionary.

fetch(document, dictionary, key)

@spec fetch(document(), value(), binary()) ::
  {:ok, value() | nil}
  | {:error,
     {error_reason(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Returns a dictionary key after resolving the dictionary itself.

read(pdf)

@spec read(binary()) ::
  {:ok, document()}
  | {:error,
     {error_reason(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Parses a PDF binary into a resolver document.

resolve(document, value)

@spec resolve(document(), value()) ::
  {:ok, value()}
  | {:error,
     {error_reason(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Resolves an indirect value in a parsed document.