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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

If you are using PDFKit, set the option

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

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)