Reputation: 196
I am having trouble using wkhtmlpdf gem on my machine. OS - ZorinOS. This is the error I am getting when trying to download or view a pdf file on the rails server -
Error: PDF could not be generated! Command Error: /home/my-user/.rvm/gems/ruby-3.0.1@somename/gems/wkhtmltopdf-binary-0.12.6.5/bin/wkhtmltopdf:61:in `<top (required)>': Invalid platform, must be running on Ubuntu 16.04/18.04/20.04 CentOS 6/7/8, Debian 9/10, archlinux amd64, or intel-based Cocoa macOS (missing binary: /home/my-user/.rvm/gems/ruby-3.0.1@somename/gems/wkhtmltopdf-binary-0.12.6.5/bin/wkhtmltopdf_zorin_16_amd64). (RuntimeError)
I tried following this command to try to resolve which I found on a GitHub issue for wkhtmltopdf_binary_gem. But this too could not solve it.
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb
sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb
sudo apt -f install
Using the command type wkhtmltopdf
I get wkhtmltopdf is /home/mu-user/.rvm/gems/ruby-3.0.1@somename/bin/wkhtmltopdf
Upvotes: 3
Views: 2955
Reputation: 214
For ubuntu 22.04 I used the latest version of the wkhtmltopdf-binary gem in Gemfile
gem 'wkhtmltopdf-binary', '~> 0.12.6.6'
check the latest version from this page https://rubygems.org/gems/wkhtmltopdf-binary
Upvotes: 3
Reputation: 23661
The issue seems to be because of the platform.
Based on your OS it is trying to search the binary for wkhtmltopdf_zorin_16_amd64
which the gem does not have.
The best solution would be to try:
creating a symlink mentioned in the GitHub issue you linked with the question - here
ln wkhtmltopdf_ubuntu_20.04_amd64.gz wkhtmltopdf_zorin_16_amd64.gz # Not tested. Give it a try
Install supported wkhtmltopdf from the website or build from the source and pass the path using wkhtmltopdf
option while generating the PDF
def show
respond_to do |format|
format.pdf do
render pdf: 'file_name',
template: 'articles/show',
wkhtmltopdf: '/usr/local/bin/wkhtmltopdf' # path to binary
end
end
Upvotes: 2