我尝试在rails 6上使用WickedPdf,但遇到此错误
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版本,做了很多事情,但都没有工作,我应该怎么做来解决这个错误?
3条答案
按热度按时间9cbw7uwe1#
好吧,这就是你的问题所在。错误消息指出:
Invalid platform, must be running on Ubuntu 14.04/16.04/18.04
。您必须从https://wkhtmltopdf.org/downloads.html安装Ubuntu 20.04版本,并手动将其指向此版本,如下所示/config/初始化器/wicked_pdf.rb
olhwl3o22#
备选案文1:
备选案文2:
piv4azn73#
我遇到了同样的错误,在做了一些研究后,我发现这个问题是由于
wkhtmltopdf-binary
,它与Ubuntu 21.04不兼容(在我的情况下)。