Skip to content

How to render HTML into PDF using
wkhtmltopdf

The real tiny Doppio factory that creates one by one PDF documents from HTML files

What is wkthmltopdf

Wkhtmltopdf is a command line tool to render HTML into PDF using a webkit rendering engine. A lot of libraries offering this feature are built upon it.

However, we warn you to use it at your own risk.

Wkhtmltopdf last stable version was released June 2020. It has been deprecated and even archived on Github since January 2023.

This means any security patch, Javascript feature, CSS feature supported by browsers after 2020 will never be supported by wkhtmltopdf. No fix will be released for newly discovered bugs or security issues. Your code can be displayed correctly on your browser and be broken when rendering to PDF.

Setup

Start by installing the command line tool on your machine.

You can find precompiled libraries here but those can be old and most likely incompatible with your current machine.

Another option is to build it from the source.

For mac users, you can install it with brew:

shell
brew install wkhtmltopdf --cask

Usage

Wkhtmltopdf command line is pretty straight forward

shell
wkhtmltopdf <source> <output>

The source can either be an URL address or the relative path to an HTML file. The output is the relative path to the rendered PDF file.

A lot of options are available. You can find the whole list here.

Restrictions

Pure HTML

Wkhtmltopdf does not go well with Javascript. If you use a framework such as Vue, React or Angular to render the HTML, the rendered PDF will likely be an empty page however long you wait for Javascript to execute.

Security issues

Using wkhtmltopdf in your application implies having another dependency and execute a binary inside your application. This can lead to a potential security breach.

The documentation warn to not use it with untrusted HTML as it could take over the server it is running on. It is your responsibility to check the HTML and sanitize it to avoid any issues.

Automation

It is not the most suitable approach if you are looking to automate PDF generation, for exemple for rendering invoices or reports. Other libraries wrap wkhtmltopdf for better use in Node, Python etc but it adds another layer of complexity and not all features could be available.

Deprecated

As we mentionned earlier, wkhtmltopdf is no being longer maintained. This means no update will be released in the future. If a security issue or a bug is discovered, it will not be fixed.

Wkhtmptopdf VS Doppio

Doppio provides a simpler, more secured and scalable solution to rendering PDF.

All it takes to render the PDF is an API call.

It is easy to use and kept up-to-date with the latest rendering engines by our team.

It executes outside your application, saving precious ressources on your server and protecting it from any security issues.

You can easily use Doppio from your terminal with just curl, without installing anything.

shell
curl --location --request POST 'https://api.doppio.sh/v1/render/pdf/direct' \
--header 'Authorization: Bearer <YOUR API KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{
  "page": {
    "pdf": {
      "printBackground": true
    },
    "goto": {
      "url": "https://example.doppio.sh/information-booklet.html",
      "options": {
        "waitUntil": ["networkidle0"]
      }
    }
  }
}' --output ./myfile.pdf
WkhtmltopdfDoppio
Type of toolSelf managed libraryHosted and managed Saas API
Maintenance Deprecated Kept up-to-date by our team
Easy setup
PDF rendering
PNG, JPG & WebP rendering
Languages supported Not full javascript support Any language
Create asynchronous workflows Good luck!
Upload delegation (S3 storage) Good luck!
HDS ready Depend on you
GDPR ready & full privacy Depend on you
Fully secured Depend on you
PricingFree (but need to be hosted and managed on your server)Free plan (400 renders / month) Paying plan from €14,90 / month
Dashboard

Grab you API key and try Doppio out : it’s free !

With our basic plan, generate up to 400 documents per month for free. No credit card required.

All rights reserved