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 color-space resource.
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 a pattern resource.
Adds an XObject reference directly.
Converts the resource collection into a PDF resource dictionary.
Types
@type resource_dictionary() :: %{optional(binary()) => PaperForge.Reference.t()}
@type t() :: %PaperForge.PageResources{ color_spaces: resource_dictionary(), fonts: resource_dictionary(), graphics_states: resource_dictionary(), patterns: resource_dictionary(), xobjects: resource_dictionary() }
Functions
Returns whether the page has any resources.
Merges two page resource collections.
Resources from the second argument replace resources with the same name in the first.
@spec new() :: t()
Creates an empty page resource collection.
@spec put_color_space(t(), binary(), PaperForge.Reference.t()) :: t()
Adds a color-space resource.
@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.
@spec put_font(t(), binary(), PaperForge.Reference.t()) :: t()
Adds a font reference directly.
Example
resources =
PaperForge.PageResources.put_font(
resources,
"F1",
reference
)
@spec put_graphics_state(t(), binary(), PaperForge.Reference.t()) :: t()
Adds an external graphics state resource.
@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".
@spec put_pattern(t(), binary(), PaperForge.Reference.t()) :: t()
Adds a pattern resource.
@spec put_xobject(t(), binary(), PaperForge.Reference.t()) :: t()
Adds an XObject reference directly.
Converts the resource collection into a PDF resource dictionary.
Empty resource groups are omitted.
Example result
%{
"Font" => %{
"F1" => reference
},
"XObject" => %{
"Im1" => image_reference
}
}