Native Elixir PDF Utilities
Native Elixir PDF Utilities brings HTML-to-PDF rendering and PDF editing directly into your Elixir application, without a browser or external PDF command-line tools. It can replace Chromium-based rendering for templates using the supported HTML/CSS features. With matched fonts and page settings, version 1.0.0 achieves less than 1% changed pixels on every compared page across 71 Chromium parity fixtures and 85 pages, including invoices, forms, purchase orders, labels, and multi-page reports.
Beyond rendering, it merges, transforms, splits, and stamps PDFs, fills forms, embeds attachments, extracts embedded text, and reads and updates metadata and bookmarks.
Document operations have configurable limits for untrusted inputs, including a five-minute deadline and a 1 GiB observed BEAM worker-memory allowance by default. Applications control concurrency. For services that render untrusted SVGs, see the scheduler, memory and cancellation limits.
Package and docs
- Package: https://hex.pm/packages/native_elixir_pdf_utilities
- API docs: https://native-elixir-pdf-utilities.hexdocs.pm/api-reference.html
- Contributing: Setup, architecture and testing
What it does
-
Tokenizer - turns PDF byte streams into structured Elixir tokens.
-
PDF information - reads page geometry and document metadata, detects encryption, and updates common metadata fields.
-
Merger - combines multiple PDF binaries into a fresh PDF with rewritten object references.
-
Page transforms and splitting - rebuild PDFs after selecting, reordering, deleting, rotating, or splitting pages.
-
Outlines and bookmarks - read or replace bookmarks, detect headings in existing PDFs, and generate bookmarks from HTML headings. Merging, transforms, and splitting preserve supported outlines.
-
Stamping and page numbers - adds text stamps, translucent watermarks, page numbers, and PDF artwork overlays to existing PDFs through incremental updates.
-
Reader and text extraction - strictly resolve embedded Unicode text from classic and modern PDFs.
-
HTML to PDF - renders a strict, document-oriented HTML/CSS subset to native PDF bytes, with examples for common workflows. It supports TrueType, CFF/CFF2, WOFF/WOFF2, selected variable-font instances and static color glyphs, with cross-platform discovery of installed system fonts. The compatibility guide lists the supported print features and deferred draft syntax. Rendering after compilation does not require Chromium, wkhtmltopdf, Node, SaaS calls, or a Rust toolchain. First-party runtime code is Elixir, including CSS colors, Unicode line breaking and HTML form-value validation. SVG images use the existing Resvg converter. Local asset loading works on Windows, macOS, and Linux.
-
PDF forms - generates named AcroForm fields from HTML by default, inspects and fills existing fields, and flattens selected fields.
-
Attachments - embeds caller-approved file bytes with MIME detection and lists embedded metadata.
HTML rendering includes native MathML equations, with the bundled STIX Two Math font, matrices and equation fragment links.
See the documentation for feature guides, configurable resource limits, and quick reference.
Installation
def deps do
[
{:native_elixir_pdf_utilities, "~> 1.2"}
]
end
Install the OTP xmerl application if your distribution packages it separately.
SVG rendering (resvg) and system font discovery (elixir_font_discovery)
both have precompiled binaries for x86-64 and ARM64 on macOS and glibc Linux,
and for x86-64 on Windows (GNU and MSVC). When compiling dependencies, allow
access to both projects’ GitHub release assets or prepopulate the
RustlerPrecompiled cache for the target platform.
On GNU/Linux, install the Fontconfig runtime library. For a musl deployment,
provide a compatible build of elixir_font_discovery or use a glibc runtime image.
License
The library source is MIT licensed. Bundled DejaVu font files use the Bitstream Vera license; WHATWG character-reference data and Adobe glyph-name data retain their respective BSD 3-Clause notices. Brotli dictionary and transform data retain Google's MIT notice. See the complete license texts.