I’m trying to use WickedPdf on rails 6 but I’m having this error
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>'
):
in my gemfile i add
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
my controller method to render pdf is
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
my html file to pdf is
<!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>
I already changed the paths, changed gem versions, and did a lot of things but nothing worked, what should I do to solve this error?
3
Answers
Well, there is your problem. The error message states:
Invalid platform, must be running on Ubuntu 14.04/16.04/18.04
. You’ll have to install the version for Ubuntu 20.04 from https://wkhtmltopdf.org/downloads.html and manually point it to this version like this/config/initializers/wicked_pdf.rb
I faced the same error, and after doing some research I found the issue is due to
wkhtmltopdf-binary
, which was not compatible with Ubuntu 21.04 (in my case). Found the solution here.Option 1:
Option 2: