rubyrubygemswkhtmltopdfwicked-pdfwkhtmltopdf-binary

Can't use wkhtmltopdf-binary due to error "PDF could not be generated!"


Trying to execute tests on project and got errors with wkhtmltopdf-binary:

Failed to execute:  
["/home/o200/.asdf/installs/ruby/2.7.3/bin/wkhtmltopdf", "--margin-top", "5", "--margin-bottom", "10", "--margin-left", "10", "--margin-right", "10", "--footer-html", "file:////tmp/wicked_footer_pdf20240903-22703-1y5cw9p.html", "file:////tmp/wicked_pdf20240903-22703-yzpxrd.html", "/tmp/wicked_pdf_generated_file20240903-22703-62f1ed.pdf"]        

Error: PDF could not be generated!         

Command Error: /home/o200/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/wkhtmltopdf-binary-0.12.6/bin/wkhtmltopdf:48:in <top (required)>': Invalid platform, must be running on Ubuntu 16.04/18.04/20.04 CentOS 6/7/8, Debian 9/10, or intel-based Cocoa macOS (missing binary: /home/o200/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/wkhtmltopdf-binary-0.12.6/bin/wkhtmltopdf_ubuntu_22.04_amd64).

(RuntimeError)
from /home/o200/.asdf/installs/ruby/2.7.3/bin/wkhtmltopdf:23:in load'         
from /home/o200/.asdf/installs/ruby/2.7.3/bin/wkhtmltopdf:23:in <main>`

Example of code:

content = "<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html> "
options = {}
WickedPdf.new.pdf_from_string(content, options)

About my system:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:    22.04
Codename:   jammy

I am tried to reinstall packages and gems - wicked_pdf and wkhtmltopdf-binary


Solution

  • You are using the wkhtmltopdf-binary gem in version 0.12.6. However, support for Ubuntu 22.04 was only added in version 0.12.6.8.

    Thus, to be able to create PDFs on Ubuntu 22.04 using this gem, you have to update the gem to at least version 0.12.6.8. Depending on your app configuration, this could be accomplished by updating your Gemfile or just by running

    bundle update wkhtmltopdf-binary