Debugging PDFKit and WKHTMLToPDF

When PDFKit errors out with an unhelpful error like: `RuntimeError (command failed (exitstatus=1): /bin/wkhtmltopdf --page-size A4 - -):`, try the following:

* Add `config.verbose = true` to its configuration
* Add `load_error_handling: 'ignore'` to its `config.default_options`
* Save the rendered HTML to a file by modifying pdfkit.rb's `to_pdf` method with this just before the `invoke` declaration.

```ruby
open('/tmp/pdfkit-source.html', 'a') { |f| f.puts @source.to_s }
```

Once you've got the html saved, you can inspect it for errors, and manually run `wkhtmltopdf` on the CLI using it as input like so:

```shell
cat /tmp/pdfkit-source.html | <the wkhtmltopdfbin command that is failing> out.pdf
```

Hopefully one of these techniques can highlight where your problems lie, and get you to a resolution.

gabrielfortuna
May 30, 2023