Rails wikedPDF错误。无法生成PDF
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rails wikedPDF错误。无法生成PDF相关的知识,希望对你有一定的参考价值。
我试图在Rails 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版本,做了很多事情,但都没有用,我应该怎么做才能避免这个错误?
答案
好吧,这就是你的问题。错误信息指出。Invalid platform, must be running on Ubuntu 14.04/16.04/18.04
. 你必须安装Ubuntu 20.04的版本,从以下地方安装 https:/wkhtmltopdf.orgdownloads.html。 并手动将其指向这个版本,就像这样
configinitializerswicked_pdf.rb。
WickedPdf.config = {
exe_path: '/path/to/correct/version'
}
以上是关于Rails wikedPDF错误。无法生成PDF的主要内容,如果未能解决你的问题,请参考以下文章