I'm trying to generate pdf from string using wicked_pdf.pdf_from_string(). String is generated from erb template.
And getting an error:
Error: Error: Failed to execute:
["/Users/bartek/.rbenv/versions/2.3.0/bin/wkhtmltopdf", "-q", "file:////var/folders/74/2xlhr9w132vd0cgkzstkhykm0000gn/T/wicked_pdf20170816-67029-16pz8e.html", "/var/folders/74/2xlhr9w132vd0cgkzstkhykm0000gn/T/wicked_pdf_generated_file20170816-67029-1c8pr5g.pdf"]
Error: PDF could not be generated!
I use:
OSX Sierra 10.12.4
Ruby 2.3.0p0
Rails 4.2.4
wicked pdf: 1.0.6, (tried also 1.0.2)
wkhtmltopdf-binary 0.9.9.3.
Update: i've install manually wkhtmltopdf binary on OSX, but in version 0.12.3. And point it manualy in wicked_pdf config, but now the render looks bad - some strange margins etc.
Should i use max 0.9.9? And if so where can i find 64bit OSX binary for that?
You should stick with 0.12.x, 0.9.9 is several years old now, and as you demonstrated, may not even run on some modern systems anymore.
In the wicked_pdf_issues project, I've been bouncing between using the wkhtmltopdf-binary gem and wkhtmltopdf-binary-edge gem. Try both and see if one works better for you. You can also use the latest on OSX through Homebrew with brew install wkhtmltopdf, which puts the binary in /usr/local/bin/wkhtmltopdf, so you'll need to point your config's exe_path to that.
The version of webkit that drives wkhtmltopdf is akin to a very old Chrome (v13), so there will be some rendering differences to a modern browser, especially if you are using FlexBox (which is not supported).
I've seen the maintainer of wkhtmltopdf recommended checking your templates (with show_as_html: true through the http://www.qtweb.net/ browser for more accurate portrayal of how it will render as a pdf through wkhtmltopdf.
Create a separate style tag or stylesheet for your PDF and tweak the CSS there.
I've joined to project and get it after previous dev. Production is with 0.9.9 and is working fine and rendering is good. Only my local dev env has problems with wicked and wkhtmltopdf binaries. There are for example some border around content of each page - looks like margins. But they do not fit page height and it is offset on each site. With 0.12.4 everything is super small :) like 1/4 of actual dimensions.
I know how to use it with local binaries, but it somehow will make deployment more difficult.
The tiny render is a bug in wkhtmltopdf version 0.12.4 when you have a high-resolution monitor hooked up (or a retina macbook screen). You can try setting dpi: 300 locally, or downgrade to 0.12.3 until a fixed version is released.
You could also mimic your production environment locally by developing in a virtualized Linux VM, thought there are definitely some drawbacks to that.
If you can check your PDFs in production (do you have a staging environment) with 0.12.x, I'd recommend you upgrade, so you don't have to deal with different versions in development and staging, but if you have to, you can add conditionals to your configuration like so:
__config/initializers/wicked_pdf.rb__
pdf_config = {}
pdf_config[exe_path] = '/usr/local/bin/wkhtmltopdf' if Rails.env.development?
WickedPDF.config = pdf_config
This will use default binary finding in other environments, but a specific version locally.
True, I will do like this right now, and will try to migrate towards 0.12.3 in production.
Thank you for your help.
Any luck?
Closing due to inactivity. Please reopen if you are still having an issue.
try bundle pristine
Most helpful comment
You should stick with 0.12.x, 0.9.9 is several years old now, and as you demonstrated, may not even run on some modern systems anymore.
In the wicked_pdf_issues project, I've been bouncing between using the
wkhtmltopdf-binarygem andwkhtmltopdf-binary-edgegem. Try both and see if one works better for you. You can also use the latest on OSX through Homebrew withbrew install wkhtmltopdf, which puts the binary in/usr/local/bin/wkhtmltopdf, so you'll need to point your config'sexe_pathto that.The version of webkit that drives wkhtmltopdf is akin to a very old Chrome (v13), so there will be some rendering differences to a modern browser, especially if you are using FlexBox (which is not supported).
I've seen the maintainer of
wkhtmltopdfrecommended checking your templates (withshow_as_html: truethrough the http://www.qtweb.net/ browser for more accurate portrayal of how it will render as a pdf through wkhtmltopdf.Create a separate style tag or stylesheet for your PDF and tweak the CSS there.