Fork of elixir-pdf-generator. It adds weasyprint as the default backend.
weasyprint
- follow official installation guide
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.
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 generationwkhtmltopdf
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.