PaperForge.PageResources (PaperForge v0.2.0)

Copy Markdown View Source

Represents the resources used by a PDF page.

A page can reference resources such as:

  • fonts;
  • images and other XObjects;
  • graphics states;
  • color spaces;
  • patterns.

PaperForge v0.2.0 currently uses fonts and image XObjects directly, while the remaining resource groups are included to keep the structure extensible.

Summary

Functions

Returns whether the page has any resources.

Merges two page resource collections.

Creates an empty page resource collection.

Adds a registered font to the page resources.

Adds a font reference directly.

Adds an external graphics state resource.

Adds a registered image as a page XObject.

Adds an XObject reference directly.

Converts the resource collection into a PDF resource dictionary.

Types

resource_dictionary()

@type resource_dictionary() :: %{optional(binary()) => PaperForge.Reference.t()}

t()

@type t() :: %PaperForge.PageResources{
  color_spaces: resource_dictionary(),
  fonts: resource_dictionary(),
  graphics_states: resource_dictionary(),
  patterns: resource_dictionary(),
  xobjects: resource_dictionary()
}

Functions

empty?(resources)

@spec empty?(t()) :: boolean()

Returns whether the page has any resources.

merge(left, right)

@spec merge(t(), t()) :: t()

Merges two page resource collections.

Resources from the second argument replace resources with the same name in the first.

new()

@spec new() :: t()

Creates an empty page resource collection.

put_color_space(resources, resource_name, reference)

@spec put_color_space(t(), binary(), PaperForge.Reference.t()) :: t()

Adds a color-space resource.

put_font(resources, font)

@spec put_font(t(), PaperForge.Font.t()) :: t()

Adds a registered font to the page resources.

The font is stored using its internal PDF resource name, such as "F1" or "F2".

Adding the same resource again replaces the existing reference.

put_font(resources, resource_name, reference)

@spec put_font(t(), binary(), PaperForge.Reference.t()) :: t()

Adds a font reference directly.

Example

resources =
  PaperForge.PageResources.put_font(
    resources,
    "F1",
    reference
  )

put_graphics_state(resources, resource_name, reference)

@spec put_graphics_state(t(), binary(), PaperForge.Reference.t()) :: t()

Adds an external graphics state resource.

put_image(resources, image)

@spec put_image(t(), PaperForge.Image.t()) :: t()

Adds a registered image as a page XObject.

Images are stored using internal names such as "Im1".

put_pattern(resources, resource_name, reference)

@spec put_pattern(t(), binary(), PaperForge.Reference.t()) :: t()

Adds a pattern resource.

put_xobject(resources, resource_name, reference)

@spec put_xobject(t(), binary(), PaperForge.Reference.t()) :: t()

Adds an XObject reference directly.

to_dictionary(resources)

@spec to_dictionary(t()) :: map()

Converts the resource collection into a PDF resource dictionary.

Empty resource groups are omitted.

Example result

%{
  "Font" => %{
    "F1" => reference
  },
  "XObject" => %{
    "Im1" => image_reference
  }
}