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
@spec add_page( PaperForge.Document.t(), PaperForge.Page.t() | (PaperForge.Page.t() -> PaperForge.Page.t()) ) :: PaperForge.Document.t()
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)
@spec add_page( PaperForge.Document.t(), keyword(), (PaperForge.Page.t() -> PaperForge.Page.t()) ) :: PaperForge.Document.t()
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
)
@spec metadata( PaperForge.Document.t(), keyword() ) :: PaperForge.Document.t()
Adds metadata to the document.
@spec new() :: PaperForge.Document.t()
Creates a new PDF document.
@spec to_binary(PaperForge.Document.t()) :: binary()
Converts the document to a complete PDF binary.
@spec write(PaperForge.Document.t(), Path.t()) :: :ok | {:error, File.posix()}
Writes the PDF to a file.
@spec write!(PaperForge.Document.t(), Path.t()) :: :ok
Writes the PDF to a file and raises if writing fails.