PaperForge (paper_forge v0.1.0)

Copy Markdown View Source

A pure Elixir PDF generation library.

PaperForge generates PDF documents directly without using browsers or external PDF rendering programs.

Summary

Functions

Adds a page to a document.

Creates a page with the given options, configures it with a function, and adds it to the document.

Adds metadata to the document.

Creates a new PDF document.

Converts the document to a complete PDF binary.

Writes the PDF to a file.

Writes the PDF to a file and raises if writing fails.

Functions

add_page(document, page)

Adds a page to a document.

It accepts either an existing PaperForge.Page struct or a function that receives a new page and returns the configured page.

Existing page

page =
  PaperForge.Page.new()
  |> PaperForge.Page.text("Hello", x: 72, y: 750)

document
|> PaperForge.add_page(page)

Builder function

document
|> PaperForge.add_page(fn page ->
  PaperForge.Page.text(page, "Hello", x: 72, y: 750)
end)

add_page(document, options, function)

Creates a page with the given options, configures it with a function, and adds it to the document.

Example

document
|> PaperForge.add_page(
  [size: :letter, orientation: :landscape],
  fn page ->
    PaperForge.Page.text(
      page,
      "Landscape page",
      x: 72,
      y: 500
    )
  end
)

metadata(document, options)

Adds metadata to the document.

new()

@spec new() :: PaperForge.Document.t()

Creates a new PDF document.

to_binary(document)

@spec to_binary(PaperForge.Document.t()) :: binary()

Converts the document to a complete PDF binary.

write(document, path)

@spec write(PaperForge.Document.t(), Path.t()) :: :ok | {:error, File.posix()}

Writes the PDF to a file.

write!(document, path)

@spec write!(PaperForge.Document.t(), Path.t()) :: :ok

Writes the PDF to a file and raises if writing fails.