Alex66
Pure Elixir PDF generation. No Chrome, no wkhtmltopdf, no NIFs, no ports. Font parsing, subsetting, hyphenation, line breaking, serialisation, encryption and signing are all Elixir/OTP.
Fork of ex_guten (Hugh Watkins, MIT), itself a port of Joe Armstrong’s erlguten. Most of the engine — TrueType/OpenType parser, Knuth-Plass line breaker, TeX hyphenation, PDF serialiser — is Hugh’s work. Git history preserved, copyright retained in LICENSE, full chain in NOTICE.
Tincture.new()
|> Tincture.page_size(:a4)
|> Tincture.register_ttf_font("Body", "Georgia.ttf")
|> Tincture.set_font("Body", 11)
|> Tincture.text_paragraph(50, 700, rich_text, 495,
align: :justified, line_break: :optimal)
|> Tincture.export()
Features
- Typography — TeX hyphenation (Liang patterns, 5 locales), Knuth-Plass global line breaking, configurable widow/orphan/hyphen penalties, GPOS kerning, GSUB ligatures
- Fonts — standard 14; TrueType/OpenType embedding, subsetting on by default (70–90% reduction)
- Layout — text boxes with spill, multi-column flow, tables with auto column widths, page templates with headers/footers/numbering, XML-driven documents
- Graphics — lines, rects, circles, Bézier paths, fill/stroke/clip; JPEG and PNG with alpha
- Documents — metadata, bookmarks, links, forms (text, choice, checkbox, radio group, push button, signature), AES-256 encryption
- Standards — tagged PDF (PDF/UA), PDF/A with built-in sRGB output intent, detached PKCS#7 signatures
- Telemetry — spans per document, page and embedded font;
:telemetryis an optional dep
Conformance
Checked with veraPDF 1.30.2 and OpenSSL 3.6, not asserted:
| Standard | Result |
|---|---|
| PDF/UA-1 (ISO 14289-1) | isCompliant=true, 106/106 rules |
| PDF/A-2b (ISO 19005-2) | isCompliant=true, 144/144 rules |
| PDF/A-2u | isCompliant=true, 146/146 rules |
| PDF/A-2a | isCompliant=true, 153/153 rules |
| PKCS#7 detached | verified by openssl cms -verify |
Example documents are committed. Reproduce:
verapdf --flavour ua1 examples/output/compliant.pdf
verapdf --flavour 2a examples/output/archival.pdf
set_pdf_a/2 writes a conformance claim into the file, so export/2 refuses to emit a document that breaks the rules it can check, listing each violation and clause. enforce: false overrides.
Install
{:tincture, "~> 0.1"}
0.x is deliberate — the API under this name is new and may move before 1.0.
1,225 tests, 89% coverage, Credo --strict clean, Dialyzer clean, CI on Elixir 1.16–1.19. Seven examples with output PDFs committed.
Hex: tincture | Hex
Docs: Tincture v0.1.0 — Documentation
Roadmap: tincture/ROADMAP.md at main · thatsme/tincture · GitHub
Examples: tincture/examples at main · thatsme/tincture · GitHub
Trending in Announcing
Other Trending Topics
BEAM There, Done That with Mat Trudel on Building Bandit and the Web Server Running Your Phoenix App
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 8- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
ryanzidago
This is awesome!
wallyfoo
Sweet! I’ve been working on a number of projects that rely on weasyprint and an apt file download for deployment. I’m looking forward to giving this a test-drive!
Alex66
Hi @wallyfoo
That apt layer is exactly what I wanted gone — Pango, cairo, GDK-PixBuf, harfbuzz, and a base image you can’t bump without holding your breath. One line in mix.exs and a release that runs anywhere the BEAM runs.
If you do give it a spin, I’d really like to hear how it goes — especially what your documents look like and where the API gets in your way. Coming from WeasyPrint you’ll notice things I can’t see from the inside.
Best
Alex66
v0.2.0
Added:
set_alpha/2— constant alpha for fill and strokelinear_gradient/7,radial_gradient/7— axial and radial shadings, any number of stopsGradients fill a rectangle and clip to it.
/ExtGStateand/Shadingare written inline into the page resource dictionary, so documents that don’t use them are byte-identical to 0.1.0.Fixed:
invoice.exsandform.exscrashed when no font was installed — Windows, and any container image without fonts.Example: tincture/examples/gradient.exs at main · thatsme/tincture · GitHub
Changelog: tincture/CHANGELOG.md at main · thatsme/tincture · GitHub
1250 tests, Elixir 1.16–1.19, no runtime dependencies.
Two notes on choices: the CRLF and example fixes are listed as clone-only because they were — worth saying so plainly rather than implying 0.1.0 users had a broken package. And the byte-identical claim is verified by the six fixture hash locks, so it’ll hold if anyone checks.
Lucassifoni
Excellent. Do you plan to support the various action types links need ? I’m mainly thinking of
/URI(which exists now),/GoTo,/GoToRfor my use case but there are a lot more like/Launchand friends. From what I’ve seen in the source it should not be too hard to add but there are a lot of link types so it might be worth thinking before adding tuple variants.Alex66
Hi @Lucassifoni
Good catch, and you’re right that tuple variants are the trap — that’s exactly what I want to avoid.
Today it’s
/URIonly for links, plus reset/submit/URL on form buttons. For the rest I’d want structs behind a behaviour rather than tuples:One dispatch point, and it means a satellite package could add an action type without the core being touched.
The real work isn’t the actions though — it’s destinations.
/GoTois trivial once you can name a target, but the destination array has eight forms (/XYZ,/Fit,/FitH,/FitV,/FitR,/FitB,/FitBH,/FitBV), each with a different arity and nulls allowed for “leave unchanged”. Underneath that sits forward references: a link on page 2 pointing at page 7, in a single-pass writer, before page 7 has an object number. I’d rather make named destinations the primary API and resolve the/Destsname tree at export than buffer and patch — which also gets/GoToRmost of the way, since remote destinations tend to be named anyway.On
/Launchand friends I’d draw the line deliberately. PDF/A prohibits/Launch,/JavaScript,/Sound,/Movie,/ResetFormand/ImportData, so implementing them lets someone build a document thatexport/2then has to refuse. Navigation and URI actions in scope, the executable ones out, and said so in the docs rather than left as an omission.It isn’t on the ordered list yet — next up are finishing the accessibility tagging, form appearance streams, then object streams — but it’s additive and collides with none of them. If you open an issue with your
/GoToRcase I’ll design the destination API against a real use rather than a guess. And you’re clearly already in the source, so if you’d rather take it on, very welcome.Best,
Alex
Lucassifoni
Hi @Alex66, I fully agree that preventing
. Plus, if you truly want to have them, you can easily use custom URI schemes and a post-process phase with another library (today I’m doing this with Pike by shelling out to Python, for example).
/Launchand friends is the right directionI’d love to contribute for GoTo and generally Dests but will be off this evening. Can this wait a few weeks on your side without blocking other developments if you also need Dests ?
Alex66
Hi @Lucassifoni
Yes, it can wait — nothing depends on it. What’s queued is accessibility tagging, then form appearance streams, then object streams, and destinations collide with none of them. Take the time you need.
One thing I’d rather settle now than in a few weeks: the destination API shape. That’s the part that’s awkward to change once it’s published — eight fit forms with different arities, and underneath them the forward-reference problem, a link on page 2 targeting page 7 in a single-pass writer. My inclination is named destinations as the primary API, with the
/Destsname tree resolved at export rather than buffering and patching. But I’d rather design that against your real/GoToRcase than against my guess. If you open an issue with what you need, we can agree the shape now and you implement whenever suits.Fair warning on cadence: 0.2.0 went out this morning, 0.3.0 lands next week, so main moves. I’ll stay out of the annotation and action code until you’ve had your run at it, so there’s nothing nasty to rebase onto.
And agreed on the custom URI scheme plus a post-process step — pikepdf is a sensible place to put that. It’s exactly the gap item 10 of the roadmap admits: reading and rewriting someone else’s file is a different problem from writing one, and for now a different toolchain.
Best,
Alex