Read more

How to fix "Exit with code 1 due to network error: ProtocolUnknownError" with wkhtmltopdf

Tobias Kraze
September 20, 2022Software engineer at makandra GmbH

New versions of wkhtmltopdf dissallow file:// URLs by default. You can allow them by passing --enable-local-file-access.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show snapshot

If you are using PDFKit, set the option

PDFKit.configure do |config|
  config.default_options = {
    enable_local_file_access: true,

This will be necessary in many setups to allow wkhtmltopdf to fetch assets (such as stylesheets) from the filesystem.

Note on security

Allowing this poses some risk when you render user input, since it might be feasible to include data from the local filesystem into the PDF. Therefore, the usual XSS protection techniques should be used.

It might be worth considering whether you can go without local file access and load assets via http://localhost or similar.

Also note that older versions of wkthmltopdf allow file:// by default.

Posted by Tobias Kraze to makandra dev (2022-09-20 16:52)