wkhtmltopdf migration

Migrate Ruby PDFKit off wkhtmltopdf

Keep the Ruby PDFKit gem. Give it the Marqius path and check one statement.

Marqius

Four printed variations of a shared document layout

Your Ruby app takes a statement it already knows how to build and gives that page to PDFKit. After a machine change, PDFKit can’t find the tool needed to write the file.

Marqius is a drop-in replacement for wkhtmltopdf. Your app can keep using Ruby PDFKit to ask for a PDF.

Why this helps

Change the program in PDFKit’s startup settings. The code that prepares the statement can stay in place while you check the PDF from a real web request.

Make your first PDF

Start with Invoice 1001 for 120.00 EUR. Open the example PDF to see what this library’s test should produce. The kit includes all 14 sample projects and a more detailed print demo for checking tables and page breaks. Open START-HERE.html after unzipping. Download the library starter kit (ZIP) · Open the library example PDF

With Docker running, unzip the demo to a fresh folder and open a terminal in the folder containing examples/. You can also start in an empty folder. The command in step 3 will fetch the files for you inside the container.

1. Open a fresh test container

Terminal
docker run --rm -it --mount "type=bind,source=$PWD,target=/proof" debian:trixie-slim bash

Run the rest of the steps in the shell that just opened. The container is a fresh Linux test environment. Your host folder is mounted as /proof, so you can open the saved PDF after the test.

2. Install the tools and Marqius

Terminal
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates curl unzip fonts-dejavu-core poppler-utils ruby ruby-bundler
mkdir -p /work
cd /work
curl -fsSLo install-marqius.sh https://marqius.com/marqius-wkhtmltopdf.sh
bash install-marqius.sh --version 0.12.8 --prefix /work/bin
export PATH="/work/bin:$PATH"
export WKHTMLTOPDF_BINARY=/work/bin/marqius-wkhtmltopdf
"$WKHTMLTOPDF_BINARY" --version
wkhtmltopdf --version

The version output should include marqius-wkhtmltopdf 0.12.8. Marqius supplies the wkhtmltopdf command inside this test container.

3. Bring the demo project into the test container

Terminal
cd /work
if [ -d /proof/examples/ruby-pdfkit ]; then
  cp -R /proof/examples .
else
  curl -fsSLo wrapper-demos.zip https://marqius.com/download/wkhtmltopdf-demo/0.12.8/marqius-wrapper-demos.zip &&
    unzip -oq wrapper-demos.zip
fi

4. Install the Ruby gems for this example

Terminal
cd examples/ruby-pdfkit
bundle install

5. Make the invoice through the gem

Terminal
bundle exec ruby render.rb /proof/invoice.pdf

6. Check that the PDF contains the right invoice

Terminal
pdfinfo /proof/invoice.pdf | grep '^Pages:'
pdftotext /proof/invoice.pdf - | grep -F 'Invoice 1001'
pdftotext /proof/invoice.pdf - | grep -F '120.00'
chmod a+r /proof/invoice.pdf

Look for one page, the invoice number and the amount. Type exit to close the test container. Open invoice.pdf in the folder you created on your computer.

How to switch your own app to Marqius

Set config.wkhtmltopdf in the Ruby PDFKit configuration. Existing PDFKit.new and to_file calls can keep the same HTML and options.

Install Marqius alongside the original. Set WKHTMLTOPDF_BINARY in the application process to the new executable's full path unless the example specifies a framework-specific variable. The Debian APT package installs /usr/bin/marqius-wkhtmltopdf. Debian installation guide · Downloads for other environments

Apply the change in Your Rails initializer or the startup code that configures the pdfkit gem. Retain the existing rendering options unless your comparison identifies a reason to change them.

ruby
PDFKit.configure do |config|
  config.wkhtmltopdf = ENV.fetch('WKHTMLTOPDF_BINARY')
end

Try it with a document you know

Test the code path you really use. If PDFKit runs as middleware, make a request that exercises it. Check the same margins and stylesheet loading so you can distinguish initialization issues from layout changes.

If the path changes in a console but not in web requests, check initialization order and restart the deployed process. This setting belongs to the Ruby gem and differs from Python pdfkit's configuration object.

Check the old and new PDFs

Save a PDF from the old setup. Make it again with the same data and fonts. Check the words, amounts and page breaks. Keep the old program path handy so you can switch back if you need to. The runnable Ruby PDFKit example exercises a sample PDF through the wrapper. The developer manual chapter records the test conditions and constraints. The public comparison scoreboard reports differences for the wkhtmltopdf and Marqius renderers.

All 14 library guides · Python pdfkit · django-wkhtmltopdf · Try Marqius for 30 days

Reader questions

Does Ruby PDFKit use the same setting as Python pdfkit?

Ruby uses PDFKit.configure and config.wkhtmltopdf. Python passes the executable path to pdfkit.configuration. Each guide shows the setting for its own library.