PaperForge.Graphics.Text (PaperForge v0.2.0)

Copy Markdown View Source

Builds PDF text drawing commands.

Supports:

  • standard PDF fonts;
  • font size;
  • text color;
  • left, center, and right alignment;
  • positioning inside a defined width.

Summary

Functions

Generates the PDF commands required to draw one line of text.

Types

option()

@type option() ::
  {:x, number()}
  | {:y, number()}
  | {:size, number()}
  | {:font, atom()}
  | {:resource_name, binary()}
  | {:color, PaperForge.Color.t()}
  | {:width, number()}
  | {:align, :left | :center | :right}

Functions

command(text, options)

@spec command(binary(), [option()]) :: iodata()

Generates the PDF commands required to draw one line of text.

Required options:

  • :x
  • :y
  • :font
  • :resource_name

Optional options:

  • :size, defaults to 12
  • :color, defaults to black
  • :width
  • :align, defaults to :left

When :width is provided, the final X coordinate is calculated according to :align.

Example

PaperForge.Graphics.Text.command(
  "Centered title",
  x: 72,
  y: 740,
  width: 450,
  align: :center,
  font: :helvetica_bold,
  resource_name: "F2",
  size: 24
)