尝试在项目上执行测试并收到 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>`
代码示例:
content = "<html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html> "
options = {}
WickedPdf.new.pdf_from_string(content, options)
关于我的系统:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
我尝试重新安装软件包和 gem - wicked_pdf 和 wkhtmltopdf-binary
您正在使用 0.12.6 版的 wkhtmltopdf-binary gem。但是,仅在 0.12.6.8 版中添加了对 Ubuntu 22.04 的支持。
因此,为了能够使用此 gem 在 Ubuntu 22.04 上创建 PDF,您必须将 gem 更新到至少 0.12.6.8 版本。根据您的应用程序配置,这可以通过更新 Gemfile 或仅通过运行来实现