PDF generation problems

We are using wkhtmltopdf tool to generate PDF reports. In the common case you needn't do any manipulations or additional settings. Sometimes, however, redmine can't find wkhtmltopdf module in OS and it should be assigned manually in the config/configuration.yml file.
  wkhtmltopdf_exe_path: <path to wkhtmltopdf tool>

If you are using Windows for Redmine server wkhtmltopdf should be installed manually from https://wkhtmltopdf.org/downloads.html

If a custom template does not generate a valid pdf document please make sure that wkhtmltopdf is correctly configured.

In case of incorrect configuration, resulting PDF will likely contain the following data:
Bad wkhtmltopdf's path: `/var/www` is not a directory.
Bundler will use `/tmp/bundler/home/www-data' as your home directory temporarily.

Access permissions problems

After update or install wkhtmltopdf or wkhtmltopdf-binary resulting PDF can contains the following error log:
Failed to execute:
["/usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf", "-q", "--encoding", "UTF-8", "--page-size", "A4", "--margin-top", "20", "--margin-bottom", "20", "--margin-left", "20", "--margin-right", "20", "--footer-left", "INV/20200416-0028", "--footer-right", "[page]/[topage]", "file:////tmp/wicked_pdf20200416-30716-7gm5cg.html", "/tmp/wicked_pdf_generated_file20200416-30716-dxtg51.pdf"]
Error: PDF could not be generated!
 Command Error: /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary- `initialize': Permission denied @ rb_sysopen - /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary- (Errno::EACCES)
    from /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary- `open'
    from /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary- `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf:22:in `load'
    from /usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf:22:in `<main>'
    from /usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
    from /usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'

To fix that problem you need to grand write permissions to wkhtmltopdf-binary bin folder. Please run the following commands from redmine folder

$ bundle show wkhtmltopdf-binary
=> /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary- 
$ chmod -R 777 /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary-

Offical wkhtmltopdf_binary gem documentation

Configuration steps

  1. Find where your wkhtmltopdf is located
    $ which wkhtmltopdf
    => /usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf
  2. Add wkhtmltopdf path to your redmine/config/configuration.yml
      wkhtmltopdf_exe_path: '/usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf'
  3. Restart Redmine instance
Was this article helpful? Yes  No
10 from 22 found this helpful