arun1

arun1

PDF generation without Chromium dependency

ChromicPDF seems to be the popular choice for pdf generation at the moment. However, I wanted to get some community input on pdf generation libraries that DO NOT have a dependency on Chromium, puppeteer etc. I am trying to avoid the dev ops overhead of managing these additional dependencies. I would rather just draw out a PDF from scratch.

Libraries I looked into:

elixir-pdf - seems functional for the basic needs.
elixir2pdf - The underlying erlang library erlguten is giving me compilation errors so I could not test this

Does anyone have any other suggestions ?

Most Liked

arun1

arun1

Thanks to everyone who replied, I ended up choosing Typst. The markdown is pretty powerful and easy to learn. There free online editor makes it easy to experiment with the markdown as well.

I don’t have any data to back this up but figured a rust library would be more performant than weasyprint in python

I could not get ex_typst to work, so I just called the typst compiler using System.cmd.

I have a base .typ file that has the layout and template variables. I use elixir’s EEx to fill out the data and write a .typ file to a temporary location. Finally I execute the typst compiler using the shell.

asianfilm

asianfilm

I’ve been using Typst, a Rust library for generating PDFs from markdown. Typst is also a pure functional language such that you can put display logic into functions in a template to keep such logic out of Elixir.

To use the latest version, 0.12, you’ll want to use it on the command line from Elixir. There is an Elixir library that packages the Rust for version 0.3 called ExTypst and a fork that updates it to version 0.9.

marceldegraaf

marceldegraaf

@arun1 not sure if you still need a solution here, but in case it helps: we’re using Gotenberg to generate PDF’s from HTML/CSS. We’re running the default Gotenberg Docker image and use the HTTP API to convert rendered Phoenix templates to PDF.

This is especially nice because we can use all the normal view helpers and Tailwind styling that we have throughout our application, and these days things like a table of contents or page numbering is pretty much solved in CSS.

Let me know if you’re interested in some example code of our setup, and the resulting PDF file!

marceldegraaf

marceldegraaf

Definitely!

To start of, this is how we deploy Gotenberg in Kubernetes. Any other platform should work as long as it can run Docker containers. We don’t change any configuration; this is just the vanilla Gotenberg 7 image.

Then we define some options for Gotenberg that are used in the API call when creating a PDF.

We then define a module that interacts with the Gotenberg API. It does an HTTP POST to the /forms/chromium/convert/html endpoint with our HTML page as a form/multipart request body.

Finally, define a module in your application that takes some data, renders an HTML file (from a Phoenix View), and then calls the previously defined Gotenberg API module to render it to PDF.

Hope this helps! Let me know if you have any questions :slight_smile:

gushonorato

gushonorato

Is generating PDFs on the server strictly required? I always generate PDFs on the client side when possible. The two main reasons are:

  1. I don’t waste CPU cycles and memory on the server with heavy libraries.
  2. JavaScript has better libraries to handle PDF generation on the client side.

I’ve been using paged.js and I’m very happy with the results. It even allows me to show a preview before printing to the client.

If you really need to create PDFs on the server side, the most popular library is PdfGenerator, which uses WKHTML instead of Chrome or Puppeteer.

Where Next?

Popular in Questions Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement