PrawnEx.Units (prawn_ex v0.3.0)

Copy Markdown View Source

Unit conversion and standard page sizes for PDF.

PDF uses points (pt) as the base unit: 1 pt = 1/72 inch.

Examples

iex> PrawnEx.Units.pt(72)
72
iex> PrawnEx.Units.inch(1)
72
iex> PrawnEx.Units.mm(25.4)
72.0
iex> PrawnEx.Units.page_size(:a4)
{595, 842}
iex> PrawnEx.Units.page_size(:letter)
{612, 792}

Summary

Functions

Convert centimetres to points.

Convert inches to points. 1 inch = 72 pt.

Convert millimetres to points.

Return page dimensions in points {width, height} for a named size.

Identity for points (PDF base unit). Use for clarity.

Functions

cm(n)

@spec cm(number()) :: float()

Convert centimetres to points.

inch(n)

@spec inch(number()) :: number()

Convert inches to points. 1 inch = 72 pt.

mm(n)

@spec mm(number()) :: float()

Convert millimetres to points.

page_size(arg1)

@spec page_size(:a3 | :a4 | :a5 | :letter | :legal | {atom(), :landscape}) ::
  {number(), number()}

Return page dimensions in points {width, height} for a named size.

Supports :a4, :letter, :legal, :a3, :a5. Optional second element :landscape flips width and height.

Examples

iex> PrawnEx.Units.page_size(:a4)
{595, 842}
iex> PrawnEx.Units.page_size({:a4, :landscape})
{842, 595}

pt(n)

@spec pt(number()) :: number()

Identity for points (PDF base unit). Use for clarity.