Wtx ~ Wt Extension Library
WtxLib
Generating PDF with wkhtmltopdf

This page discusses the steps necessary to take a document (aka; web-page) from within Wt and convert it to a well-formatted, well-behaved PDF file. The value of these techniques is high since Wt makes generating and manipulating HTML pages quite easy, and when combined with some good HTML layout techniques, it becomes possible to produce web-pages that look good in a browser as well as a PDF file.

Disclaimer: these techniques are my own, after much trial and error. These techniques are in no way to be confused with the "right way". Use what you can, your mileage may vary.

Additional Disclaimer: Note that Wt includes some objects for manipulating PDF files: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WPdfImage.html I have not taken the time to review these objects or attempt to employ them. When I am able to I will and then produce a complimentary set of documents to match.

Since we're talking about using wkhtmltopdf.org to generate a PDF document from a HTML file, let's talk about specific use cases. It's one thing to take any simple webpage or website and run it through wkhtmltopdf and get a PDF file of the same. But, when it comes to generating things like "specifically formatted" webpage, similar to those that might represent an 'invoice' or 'report' then some tips and tricks and techniques are in order. There are plenty of tutorials available on the web for simple basic use cases. This document is specific to a "formatted result" outcome.

Let's Begin

Step 1 ~ Installation
Get wkhtmltopdf installed. I can't advise you on how to do that, it depends on your platform. You should be able to call upon wkhtmltopdf from the command line like so;

Calling wkhtmltopdf

mark@lsus1:~/projects/wt/Wtx$ wkhtmltopdf
You need to specify atleast one input file, and exactly one output file
Use - for stdin or stdout
Name:
wkhtmltopdf 0.12.2.4

https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2000