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 10

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

Alex66

Alex66 OP

v0.3.0.

Tagged link annotations were never referenced from the structure tree: no /OBJR in the /Link element, no /StructParent on the annotation, /ParentTree mapping pages only. veraPDF reported 106/106 because no corpus document contained a link annotation.

Fixed. Link annotations associated with a structure element are now indirect objects, carry /StructParent, and are referenced by /OBJR from the /Link element; /ParentTree carries both value shapes. /Contents is required on tagged links (ISO 14289-1 7.18.1, 7.18.5), no default, export/2 refuses without it. Untagged links stay inline and serialise byte-identically.

Corpus now includes a tagged link. Added a test asserting which structure tags the corpus exercises — it found H3–H6 had never been validated. 37 tags, 18 exercised, 19 not. Two known defects in the README: Note missing /ID (7.9), and form widgets, which need a Form structure element that doesn’t exist yet.

veraPDF runs in CI over six documents; reports uploaded as artifacts.

Two behaviour breaks: object renumbering in tagged documents, and export/2 rejecting documents it previously wrote.

alvinkatojr

alvinkatojr

I’m very late to this, but like everyone has said: AMAZING STUFF!

Once again, I’m in awe of the dedication of members of the Elixir community. This is the 2nd PDF library I’ve seen for Elixir and each one is unique in its own way. Thank you for the good work!

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
pferriby
Introductory paragraph I’ll be looking for a keen junior or someone that has a couple of years experience in the real world (so you’ve be...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews