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 or replaces a named destination in the PDF catalog.
Adds a new indirect object.
Adds a PDF outline/bookmark item that points to a page.
Adds a page reference to the page tree.
Embeds a file in the PDF and associates it with the document catalog.
Registers a reusable flow component receiving an assigns map.
Sets the document default font key.
Fetches an object by reference.
Fetches an object by reference and raises when missing.
Fetches a page template.
Registers fallback font keys for text that a primary TrueType font cannot render.
Creates a new PDF document.
Returns the number of indirect objects.
Returns indirect objects sorted by identifier.
Registers a reusable page template.
Adds a metadata information dictionary.
Registers and reuses a standard PDF font.
Registers and reuses an embedded TrueType font.
Registers a TrueType font family.
Registers and deduplicates a supported image.
Registers and deduplicates a JPEG image.
Resolves the font key for text options, including default fonts and registered font-family variants.
Resolves a page template and all of its :extends ancestors.
Resolves a font for an entire text run, applying registered fallbacks when needed.
Registers a named document style used by PaperForge.Flow blocks.
Updates an existing indirect object.
Records Unicode text used by an embedded TrueType font.
Types
@type t() :: %PaperForge.Document{ components: %{optional(atom()) => function()}, compress: boolean(), default_font: atom(), font_fallbacks: %{optional(atom()) => [atom()]}, font_families: %{optional(atom()) => %{optional(atom()) => atom()}}, font_program_registry: %{optional(binary()) => PaperForge.Reference.t()}, font_registry: PaperForge.FontRegistry.t(), font_source_data: %{optional(atom()) => binary()}, image_registry: PaperForge.ImageRegistry.t(), info_reference: PaperForge.Reference.t() | nil, last_outline_reference: PaperForge.Reference.t() | nil, named_destinations: %{optional(binary()) => list()}, next_object_id: pos_integer(), objects: %{optional(pos_integer()) => PaperForge.Object.t()}, outline_count: non_neg_integer(), outlines_reference: PaperForge.Reference.t() | nil, page_templates: %{optional(atom() | binary()) => keyword()}, pages_reference: PaperForge.Reference.t(), pdf_version: binary(), root_reference: PaperForge.Reference.t(), styles: %{optional(atom() | binary()) => keyword()} }
Functions
Adds or replaces a named destination in the PDF catalog.
@spec add_object(t(), term()) :: {t(), PaperForge.Reference.t()}
Adds a new indirect object.
@spec add_outline(t(), binary(), PaperForge.Reference.t(), keyword()) :: t()
Adds a PDF outline/bookmark item that points to a page.
@spec append_page(t(), PaperForge.Reference.t()) :: t()
Adds a page reference to the page tree.
Embeds a file in the PDF and associates it with the document catalog.
@spec component(t(), atom(), (map() -> PaperForge.Flow.t())) :: t()
Registers a reusable flow component receiving an assigns map.
Sets the document default font key.
@spec fetch_object(t(), PaperForge.Reference.t()) :: {:ok, PaperForge.Object.t()} | :error
Fetches an object by reference.
@spec fetch_object!(t(), PaperForge.Reference.t()) :: PaperForge.Object.t()
Fetches an object by reference and raises when missing.
Fetches a page template.
Registers fallback font keys for text that a primary TrueType font cannot render.
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 totrue.:pdf_version— PDF header version. Defaults to"1.7".:default_font— default font key for text operations. Defaults to:helvetica.
@spec object_count(t()) :: non_neg_integer()
Returns the number of indirect objects.
@spec objects(t()) :: [PaperForge.Object.t()]
Returns indirect objects sorted by identifier.
Registers a reusable page template.
@spec put_metadata(t(), PaperForge.Metadata.t()) :: t()
Adds a metadata information dictionary.
@spec register_font(t(), atom()) :: {t(), PaperForge.Font.t()}
Registers and reuses a standard PDF font.
Registers and reuses an embedded TrueType font.
Registers a TrueType font family.
Supported variants are :regular, :bold, :italic, and
:bold_italic. Each variant accepts the same options as
register_font/3, usually path: "Font.ttf" or data: binary.
@spec register_image(t(), binary()) :: {t(), PaperForge.Image.t()}
Registers and deduplicates a supported image.
JPEG and PNG binaries are currently supported.
@spec register_jpeg(t(), binary()) :: {t(), PaperForge.Image.t()}
Registers and deduplicates a JPEG image.
Resolves the font key for text options, including default fonts and registered font-family variants.
Resolves a page template and all of its :extends ancestors.
Resolves a font for an entire text run, applying registered fallbacks when needed.
Registers a named document style used by PaperForge.Flow blocks.
@spec update_object( t(), PaperForge.Reference.t(), (term() -> term()) ) :: t()
Updates an existing indirect object.
@spec use_font_text(t(), atom(), binary()) :: {t(), PaperForge.Font.t()}
Records Unicode text used by an embedded TrueType font.
PaperForge keeps the embedded font file intact, but subsets the PDF
width array and /ToUnicode map to the glyphs that have actually
been used so far.