Skip to content

Create PDFs with weasyprint, wkhtmltopdf or puppeteer/chromium from Elixir.

License

Notifications You must be signed in to change notification settings

STUDITEMPS/elixir-pdf-generator

 
 

Repository files navigation

PDF Generator

Fork of elixir-pdf-generator. It adds weasyprint as the default backend.

Requirements

Usage

  PdfGenerator.generate("<html><body><p>Hi there!</p></body></html>", shell_params: ["-e", "utf-8"]])

-e utf-8 explicitly sets file encoding. If you don't set encoding explicitly then some special characters (like ü might not be rendered correctly)

By default weasyprint backend is used. Please note that weasyprint backend will ignore page_size option: use @page at-rule to set page size and orientation.

You can explictly set path to weasyprint if it's not on available on PATH:

config :pdf_generator,
  weasyprint_path: "/path/to/weasyprint"

For all other configuration options and API information consult docs of original repo.

FAQ

Why? None of the existing backends were suitable because:
  • chrome is a moving target, you never know when update to chrome will subtly (or less so) break the pdf generation
  • wkhtmltopdf uses very outdated version of WebKit (status page). Styling is very difficult.

After some reasearch, we decided to use weasyprint and re-use existing code from elixir-pdf-generator to handle temporary file creation, cleanup etc.

How do I change page orientation?

Use @page at-rule to set size and orientation (in your css stylesheet).

@page {
  size: A4 landscape;
}
How do I sync with source repo?

Use master branch of this repository and use GitHub UI to sync with source repo. Afterwards rebase weasyprint branch on the current master branch.

Do not add any commits to master! Doing so will make syncing with source repo harder.

About

Create PDFs with weasyprint, wkhtmltopdf or puppeteer/chromium from Elixir.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 94.7%
  • Makefile 5.3%