PaperForge.Document (PaperForge v0.2.0)

Copy Markdown View Source

Represents a PDF document and manages its indirect objects.

The document maintains the page tree, catalog, fonts, images, metadata, compression configuration, and indirect-object numbering.

Summary

Functions

Adds a new indirect object.

Adds a page reference to the page tree.

Fetches an object by reference.

Fetches an object by reference and raises when missing.

Creates a new PDF document.

Returns the number of indirect objects.

Returns indirect objects sorted by identifier.

Adds a metadata information dictionary.

Registers and reuses a standard PDF font.

Registers and deduplicates a supported image.

Registers and deduplicates a JPEG image.

Updates an existing indirect object.

Types

t()

@type t() :: %PaperForge.Document{
  compress: boolean(),
  font_registry: PaperForge.FontRegistry.t(),
  image_registry: PaperForge.ImageRegistry.t(),
  info_reference: PaperForge.Reference.t() | nil,
  next_object_id: pos_integer(),
  objects: %{optional(pos_integer()) => PaperForge.Object.t()},
  pages_reference: PaperForge.Reference.t(),
  pdf_version: binary(),
  root_reference: PaperForge.Reference.t()
}

Functions

add_object(document, value)

@spec add_object(t(), term()) :: {t(), PaperForge.Reference.t()}

Adds a new indirect object.

append_page(document, page_reference)

@spec append_page(t(), PaperForge.Reference.t()) :: t()

Adds a page reference to the page tree.

fetch_object(document, reference)

@spec fetch_object(t(), PaperForge.Reference.t()) ::
  {:ok, PaperForge.Object.t()} | :error

Fetches an object by reference.

fetch_object!(document, reference)

@spec fetch_object!(t(), PaperForge.Reference.t()) :: PaperForge.Object.t()

Fetches an object by reference and raises when missing.

new(options \\ [])

@spec new(keyword()) :: t()

Creates a new PDF document.

The initial objects are the page tree and catalog. Fonts are registered on demand when pages are compiled.

Options

  • :compress — enables Flate compression. Defaults to true.
  • :pdf_version — PDF header version. Defaults to "1.7".

object_count(document)

@spec object_count(t()) :: non_neg_integer()

Returns the number of indirect objects.

objects(document)

@spec objects(t()) :: [PaperForge.Object.t()]

Returns indirect objects sorted by identifier.

put_metadata(document, metadata)

@spec put_metadata(t(), PaperForge.Metadata.t()) :: t()

Adds a metadata information dictionary.

register_font(document, font_key)

@spec register_font(t(), atom()) :: {t(), PaperForge.Font.t()}

Registers and reuses a standard PDF font.

register_image(document, image_data)

@spec register_image(t(), binary()) :: {t(), PaperForge.Image.t()}

Registers and deduplicates a supported image.

JPEG and PNG binaries are currently supported.

register_jpeg(document, jpeg_data)

@spec register_jpeg(t(), binary()) :: {t(), PaperForge.Image.t()}

Registers and deduplicates a JPEG image.

update_object(document, reference, update_function)

@spec update_object(
  t(),
  PaperForge.Reference.t(),
  (term() -> term())
) :: t()

Updates an existing indirect object.