This is an occasional error i receive, not sure of the cause, because it you come back a few minutes later, the problem disappears.
full message
Error: Failed to execute:
["/var/www/myapp/shared/bundle/ruby/2.1.0/bin/wkhtmltopdf", "-q", "file:///tmp/wicked_pdf20150630-30571-1f9qkcc.html", "/tmp/wicked_pdf_generated_file20150630-30571-hqfxd7.pdf"]
Error: PDF could not be generated!
Command Error: QPainter::begin: Paint device returned engine == 0, type: 2
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::translate: Painter not active
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::setOpacity: Painter not active
QPainter::setFont: Painter not active
respond_to do |format|
format.html
format.pdf do
render pdf: 'invoice',
layout: 'pdf.html.erb',
show_as_html: params[:debug].present?
end
Does anyone have an idea? or perhaps just a way of trapping the error and redirecting to an error page ( asking to try again in a few minutes, if this is a concurrency issue )
+1
Same problem!
gem 'wicked_pdf', '~> 1.0', '>= 1.0.6'
gem 'wkhtmltopdf-binary-edge', '~> 0.12.3.0'
Ruby 2.2.0
Rails 4.2.2
Any answer would be appreciated!
@PirunSeng since I stopped using the wkhtmltopdf-binary gem and decided to install the library, haven't seen this error. I suggest you do it too.
@cesc1989 sounds good! May you give more detail please? What is the library you mentioned? And how can I install that?
@PirunSeng You can install wkhtmltopdf through your package manager, or download a precompiled binary from http://wkhtmltopdf.org/downloads.html, and point to the binary location in an initializer like this:
WickedPdf.config = {
exe_path: '/usr/local/bin/wkhtmltopdf'
}
I tried to do a little research into why this is happening for some people, and though I'm not positive this is this specific issue, I have seen reports of the "painter" not being able to draw on the virtual web browser because of the viewport having an ambiguous height or width...as to why it doesn't happen all the time, I'm not sure.
@PirunSeng Are you using Ubuntu 14.04? I've installed wkhtmltopdf for both 32 and 64 bit versions using these scripts:
apt-get install xfonts-75dpi
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2/wkhtmltox-0.12.2_linux-trusty-i386.deb
dpkg -i wkhtmltox-0.12.2_linux-trusty-i386.deb
apt-get install openssl build-essential xorg libssl-dev xfonts-75dpi
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2/wkhtmltox-0.12.2_linux-trusty-amd64.deb
dpkg -i wkhtmltox-0.12.2_linux-trusty-amd64.deb
Good luck!
@unixmonkey Thanks very much for your answer. I've checked the issues you mentioned, but none of those is related to my case. Plus, I've just installed wkhtmltopdf as you mentioned and followed @cesc1989 scripts. I don't know why the pdf is rendered without adding the configuration in the initializer in my case.
@cesc1989 Thanks very much for your answer since I just in stall xorg and xfonts-75dpi while the other were already installed. The pdf is rendered now, cool :+1:
Anyway, I've got a problem rendering unicode character. The Unicode characters become black boxes.
I've already had "<meta charset='utf-8' />" in the header. I cannot figure the problem of that black boxes. You almost solve my problem.
Hope you can help me with this last one, thanks!
@unixmonkey Until now, I've been looking around another issues, and I found out that it is the problem with the fonts, and seen you mentioned here #353 that it might be the server has no correct fonts installed. I tried installing the fonts then. I've installed 'ttf-liberation' in my case. Plus, I also added <meta http-equiv="content-type" content="text/html; charset=utf-8" /> in my header. However, the black boxes still don't go away.
Hope you can help, thanks!
Updated!
Heh @unixmonkey ! I've solved my problem by installing the right font packages. In my case, I install 'fonts-khmeros-core', but not 'ttf-liberation'.
Actually, I did a fast research on 'ttf-liberation'. I checked its fonts support, and I found out that there is a 'Catalan' font which I thought that it is readable for Khmer fonts. That's why I decided to installed it. I just realize that it doesn't help, so I just removed it as well.
Just now, I've tried looking for fonts installed in my local environment, and I found 'ttf-khmeros-core' installed, so I immediately try installing it on my the production server. Everything works just fine as expected.
Cheers :+1:
Thanks so much for letting me know what worked for you for this specific issue! I'm sure it will help others in the future. I didn't think that this would be font-related, but am happy to be wrong!
@timvoet I know it's been awhile, but does this appear to be the problem in your case also? It gives me pause that it seems to be only an intermittent issue for you.
My problem was intermittent, I haven't had a case since I upgraded my server. For various reasons, the server that was generating the pdf's would sometimes spike to 80% of memory used, on peak days. I upgraded the machine and haven't had an issue since.
@PirunSeng Can you verify if you were getting the _exact_ same error (including the type number) as in the original post?
QPainter::begin: Paint device returned engine == 0, type: 2
I know there are other "types". It might be nice if I could emit a special error message that could point someone in the right direction if we can determine a possible cause.
@unixmonkey This is the error I got.
Error: Failed to execute: ["/var/www/myapp/shared/bundle/ruby/2.2.0/bin/wkhtmltopdf", "-q", "--header-html", "file:////tmp/wicked_header_pdf20160513-4965-nwchqi.html", "--footer-right", "[page] of [topage]", "--footer-html", "file:////tmp/wicked_footer_pdf20160513-4965-s7uqlc.html", "file:////tmp/wicked_pdf20160513-4965-4ztapm.html", "/tmp/wicked_pdf_generated_file20160513-4965-c3yjta.pdf"] Error: PDF could not be generated! Command Error: /var/www/myapp/shared/bundle/ruby/2.2.0/gems/wkhtmltopdf-binary-edge-0.12.3.0/libexec/wkhtmltopdf-linux-amd64: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory
I found something like 'Error: Failed to execute...' and 'Error: PDF could not be generated!...' in the original post which are similar to mine, that is why I come up with my questions here as well.
Hope you can figure out the exact common cause.
the installation on my ubuntu server 16.04 of these lines fixed the issue...
"apt-get install openssl build-essential xorg libssl-dev xfonts-75dpi"
thanks to @cesc1989
I had this issue too, but in my case I had the config/initializers/wicked_pdf.rb file with something like this :
# WickedPDF Global Configuration
#
# Use this to set up shared configuration options for your entire application.
# Any of the configuration options shown here can also be applied to single
# models by passing arguments to the `render :pdf` call.
#
# To learn more, check out the README:
#
# https://github.com/mileszs/wicked_pdf/blob/master/README.md
WickedPdf.config = {
# Path to the wkhtmltopdf executable: This usually isn't needed if using
# one of the wkhtmltopdf-binary family of gems.
# exe_path: '/usr/local/bin/wkhtmltopdf',
# or
# exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
# Layout file to be used for all PDFs
# (but can be overridden in `render :pdf` calls)
# layout: 'pdf.html',
}
And then in the config/environments/development.rb and config/environments/production.rb file I had also :
# frozen_string_literal: true
Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the
# project's package.json
# config.webpacker.check_yarn_integrity = false
# Settings specified here will take precedence over those in
# config/application.rb.
# ...
WickedPdf.config = {
exe_path: '/usr/bin/wkhtmltopdf'
}
The later was ignored so that the path to the wkhtmltopdf binary file was like /var/www/myapp/shared/bundle/ruby/2.4.0/bin/wkhtmltopdf.
Moving the exe_path config in the initialiser and removing it from the env files fixed it.
https://askubuntu.com/questions/651244/unable-to-install-wk-deb
Works for me following the steps in link above!!
Most helpful comment
the installation on my ubuntu server 16.04 of these lines fixed the issue...
"apt-get install openssl build-essential xorg libssl-dev xfonts-75dpi"
thanks to @cesc1989