August 5, 2021

wkhtmltopdf – Generating PDF and Images

wkhtmltopdf is amazing  open source (LGPLv3) command line tool wkhtmltopdf to render HTML to PDF and various image formats using the Qt WebKit rendering engine. These run entirely “headless” and do not require any service.

There is also a C library, if you’re into that kind of thing.

How to use wkhtmltopdf ?

  1. Download a precompiled binary or build from source
  2. Create your HTML document that you want to convert into a PDF (or image)
  3. Run your HTML document through the tool.
    For example, if I really like the treatment LiferayUI has done to their logo today and want to capture it forever as a PDF:wkhtmltopdf http://liferayui.com liferayui.pdf

Additional options

That’s amazing, I’ve always wanted to turn LiferayUI homepage into a PDF, but I want a table of contents as well.

There are lot’s of command line options. You can check out the auto-generated wkhtmltopdf options.

You can also add custom Header and Footer in PDF using page option.

Leave a Reply

Your email address will not be published. Required fields are marked *