config/configuration.yml
file.
default: 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, the 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. /usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf
Access permissions problems
After update or installwkhtmltopdf
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-0.12.5.4/bin/wkhtmltopdf:39:in `initialize': Permission denied @ rb_sysopen - /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf_ubuntu_16.04_amd64 (Errno::EACCES) from /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf:39:in `open' from /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf:39:in `<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 grant 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-0.12.5.4 $ chmod -R 777 /usr/local/rvm/gems/ruby-2.4.1/gems/wkhtmltopdf-binary-0.12.5.4/bin/
Offical wkhtmltopdf_binary gem documentation
Configuration steps
- Find where your
wkhtmltopdf
is located$ which wkhtmltopdf => /usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf
- Add
wkhtmltopdf
path to yourredmine/config/configuration.yml
default: wkhtmltopdf_exe_path: '/usr/local/rvm/gems/ruby-2.4.1/bin/wkhtmltopdf' ...
- Restart Redmine instance
Docker Container
If the problem appears to you on a Redmine Docker Container, then please add this missed library to the Docker image to fix the problem:
apt-get install libxrender1
Bitnami Redmine virtual machine
Determine the location of the Ruby binary by running the command:
which ruby
Create a symbolic link to the Ruby binary using the following command:
sudo ln -s /opt/bitnami/ruby/bin/ruby /usr/bin/ruby
Set the necessary permissions for the library using the following commands
bundle show wkhtmltopdf-binary
chmod -R 777 /opt/bitnami/redmine/vendor/bundle/ruby/3.0.0/gems/wkhtmltopdf-binary-0.12.6.6/bin/
Install the dependencies for wkhtmltopdf-binary by running the following commands:
sudo apt-get update
sudo apt-get install libxrender1