What is wkhtmltopdf?

Updated

wkhtmltopdf is an open source (LGPLv3) command line tool that renders HTML into PDF using the Qt WebKit rendering engine. Its companion tool, wkhtmltoimage, does the same for various image formats. Both run entirely "headless," meaning they don't require a display or display service — so they work on servers, in CI pipelines, and on machines without a graphical environment. If you need to turn a web page or a local HTML file into a PDF or image from a script or terminal, this is what the tool is for.

What it does

  • HTML → PDF: Point it at a URL or a local HTML file and get a PDF out.
  • HTML → image: The sibling tool wkhtmltoimage produces image formats instead of PDF.
  • Headless operation: No display server needed, which makes it suitable for automated and server-side use.
  • C library available: Beyond the command line tools, there is a C library if you want to integrate the rendering into your own program.

Basic usage

The workflow is three steps, as described on the project site:

  1. Download a precompiled binary or build from source.
  2. Create the HTML document you want to convert (or use an existing URL).
  3. Run the document through the tool.

A minimal example from the documentation:

wkhtmltopdf http://google.com google.pdf

This fetches the page and writes it to google.pdf in the current directory. The same pattern applies to local HTML files — pass the file path instead of a URL.

Additional options

The command line accepts many options beyond the basic invocation. For example, you can add a table of contents to the generated PDF. The project points users to its auto-generated wkhtmltopdf manual for the full list of flags and settings.

When it fits — and when it might not

Consider wkhtmltopdf if… Look elsewhere if…
You want a command line tool to batch-convert HTML to PDF You need a GUI application
You're running headless (servers, containers, CI) Your environment can't run Qt WebKit-based rendering
You want an LGPLv3-licensed tool you can script You need to embed rendering via a C library and prefer a different language binding
You're generating invoices, cards, or similar documents from HTML —

The project's own examples include generating invoices, creating birthday cards, and simply saving a web page as a PDF — anything where HTML is your source format and PDF or an image is your target.

Project background

wkhtmltopdf was originally created by Jakob Truelsen and is maintained by Ashish Kulkarni. It is distributed under the LGPLv3 license. Downloads, documentation, and status information are available from the project site.