Let’s start from the obvious. If you using WickedPDF in 2023 it’s a little bit more problematic than just having issues with PDF generation from time to time. It means that you are building your PDF markups with tables, not using modern CSS abilities like flex and grids. It must be hard. But probably it’s because dealing with PDFs was difficult the last time you had to do it. But no matter what, the time has come. You need to up your PDF game. wkhtmltopdf is deprecated. Let’s go over your options.
Wicked PDF
So for our example, let’s consider that your app PDF controller action looks more or less like this:
Grover
grover feels almost like drop-in replacement for your WickedPDF. We only need to replace pdf generation code with something like that:
Ferrum
Grover is good, but it require you to have puppeteer in the system. What if you using importmaps and it makes no sense to include npm in your project for puppeteer only.
That is where Ferrum shines. Let’s take a look at this approach:
One important thing to mention for all of these examples, is that if you are importing css into your pdf layouts, you probably still like to keep wicked_pdf gem in your gem file for a bunch of magic around that. I honestly do not know, why Rails Core team keeps neglecting these things in Asset Pipeline API, that is obviously needed in both PDF and Mail complex scenarios, but only provided here and as is. Maybe I missing something.
There are also some half-cooked approach like this that can replace that code:
Place it in ApplicationHelper and you good to go.
Lambda Function
If you already utilizing AWS Lambda you can go in a different direction, and try to spin your headless Chrome there:
Additional details can be found on package site.
And for Rails client to that: