Alex66

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; :telemetry is 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

Showing Posts 1 to 8

ryanzidago

ryanzidago

This is awesome!

wallyfoo

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

Alex66 OP

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

Alex66 OP

v0.2.0

Added:

  • set_alpha/2 — constant alpha for fill and stroke
  • linear_gradient/7, radial_gradient/7 — axial and radial shadings, any number of stops

Gradients fill a rectangle and clip to it. /ExtGState and /Shading are written inline into the page resource dictionary, so documents that don’t use them are byte-identical to 0.1.0.

Fixed:

  • Standard font metrics parsed to nothing on a CRLF checkout. Windows clones got 44 test failures. Packages from Hex were never affected.
  • invoice.exs and form.exs crashed 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

Lucassifoni

Excellent. Do you plan to support the various action types links need ? I’m mainly thinking of /URI (which exists now), /GoTo, /GoToR for my use case but there are a lot more like /Launch and 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

Alex66 OP

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 /URI only for links, plus reset/submit/URL on form buttons. For the rest I’d want structs behind a behaviour rather than tuples:

%Tincture.Action.GoTo{dest: %Tincture.Destination{page: 3, fit: {:fit_h, 700}}}

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. /GoTo is 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 /Dests name tree at export than buffer and patch — which also gets /GoToR most of the way, since remote destinations tend to be named anyway.

On /Launch and friends I’d draw the line deliberately. PDF/A prohibits /Launch, /JavaScript, /Sound, /Movie, /ResetForm and /ImportData, so implementing them lets someone build a document that export/2 then 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 /GoToR case 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

Lucassifoni

Hi @Alex66, I fully agree that preventing /Launch and friends is the right direction :slight_smile: . 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).

I’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

Alex66 OP

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 /Dests name tree resolved at export rather than buffering and patching. But I’d rather design that against your real /GoToR case 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

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New

Other Trending Topics Top

ancatrusca
New episode covering Bandit’s engineering in more depth than I’ve seen elsewhere. Stack trace clarity. One process per connection means ...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews