我正在尝试在导轨6上使用WikerdPdf,但是出现此错误
RuntimeError (Failed to execute:
["/home/guilherme/.rbenv/versions/2.7.1/bin/wkhtmltopdf", "file:////tmp/wicked_pdf20200531-14069-p9pvre.html", "/tmp/wicked_pdf_generated_file20200531-14069-8mk29k.pdf"]
Error: PDF could not be generated!
Command Error: /home/guilherme/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf:45:in `<top (required)>': Invalid platform, must be running on Ubuntu 14.04/16.04/18.04 CentOS 6/7/8, Debian 8/9/10, or intel-based macOS (missing binary: /home/guilherme/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/wkhtmltopdf-binary-0.12.5.4/bin/wkhtmltopdf_ubuntu_20.04_amd64). (RuntimeError)
from /home/guilherme/.rbenv/versions/2.7.1/bin/wkhtmltopdf:23:in `load'
from /home/guilherme/.rbenv/versions/2.7.1/bin/wkhtmltopdf:23:in `<main>'
):
在我的gemfile中添加
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
我呈现pdf的控制器方法是
def gera_contrato
cliente = Cliente.find_by_id(params[:cliente])
@cnpj = cliente.local.cnpj
@razao = cliente.local.razao
@fantasia = cliente.local.fantasia
@nome = cliente.nome
@cpf = cliente.cpf
@rg = cliente.rg
render pdf: 'contrato', handlers: [:erb], formats: [:html]
end
我的html文件为pdf
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
<%= wicked_pdf_stylesheet_link_tag "pdf" -%>
</head>
<body>
<h1><%= @cnpj %></h1>
<h1><%= @razao %></h1>
<h1><%= @fantasia %></h1>
<h1><%= @nome %></h1>
<h1><%= @cpf %></h1>
<h1><%= @rg %></h1>
</body>
</html>
已经更改了路径,更改了gem版本,做了很多事情,但是没有任何效果,我应该怎么做才能解决这个错误?
答案 0 :(得分:1)
好吧,这是您的问题。错误消息指出:Invalid platform, must be running on Ubuntu 14.04/16.04/18.04
。您必须从https://wkhtmltopdf.org/downloads.html安装适用于Ubuntu 20.04的版本,并手动将其指向此版本
/config/initializers/wicked_pdf.rb
WickedPdf.config = {
exe_path: '/path/to/correct/version'
}