Here's the full error I'm getting in the Rails debugging mode rendering:
Failed to execute: "/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf" -q "file:////var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf20180719-13653-79d82d.html" "/var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf_generated_file20180719-13653-qaf41r.pdf" Error: PDF could not be generated! Command Error:
And here's the console output:
Rendered confidentiality_agreements/ca_template_for_rs.html.erb (1.3ms)
"***************\"/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf\" -q \"file:////var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf20180719-13653-79d82d.html\" \"/var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf_generated_file20180719-13653-qaf41r.pdf\" ***************"
Completed 500 Internal Server Error in 778ms
RuntimeError (Failed to execute:
"/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf" -q "file:////var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf20180719-13653-79d82d.html" "/var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf_generated_file20180719-13653-qaf41r.pdf"
Error: PDF could not be generated!
Command Error: ):
app/controllers/confidentiality_agreements_controller.rb:43:in `create'
The line in the create method it's talking about is this:
raw_pdf = WickedPdf.new.pdf_from_string(html)
And html there is a string that is well formed HTML.
I'm confused, because there is strangely little messaging around what's going wrong.
That error message comes from this line, meaning it somehow created a PDF, but the file was empty.
A few things I might check to debug this:
Does executing wkhtmltopdf on the command-line work for you?
/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf https://google.com google.pdf
Does a simpler html document work for you in the Rails console?
raw_pdf = WickedPdf.new.pdf_from_string('<!doctype html><html><head><title>Hello</title></head><body><h1>Hello, world!</h1></body></html>')
Is the directory the tempfiles are written to and read from have permission to write and save files from your app?
If all else fails, you can gem install pry and bundle open wicked_pdf, and drop a require 'pry'; binding.pry around this line, restart your rails server (to pick up the change in the gem source), then when you hit pry's debugging breakpoint inspect the contents of the html tempfiles in the command to see if they have issues.
You can also execute the command from the command-line yourself here.
Don't forget to remove the require 'pry'; binding.pry line when you are done, or you can bundle pristine wicked_pdf if you tried making other edits, to re-download and reinstall the gem to overwrite any edits you might have made.
Please let me know how it goes and report your findings, if any!
/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf https://google.com google.pdf on the command line seems to do nothing at all.raw_pdf = WickedPdf.new.pdf_from_string('<!doctype html><html><head><title>Hello</title></head><body><h1>Hello, world!</h1></body></html>') gives a similar error:"***************\"/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf\" -q \"file:////var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf20180719-29666-1qlhegv.html\" \"/var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf_generated_file20180719-29666-1crhyj1.pdf\" ***************"
RuntimeError: Failed to execute:
"/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf" -q "file:////var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf20180719-29666-1qlhegv.html" "/var/folders/hq/xgy6hpf56xb00g8clcmgg__m0000gn/T/wicked_pdf_generated_file20180719-29666-1crhyj1.pdf"
Error: PDF could not be generated!
Command Error:
from /Users/nhinchey/.rvm/gems/ruby-2.2.4/gems/wicked_pdf-0.10.2/lib/wicked_pdf.rb:79:in `rescue in pdf_from_string'
Looking at that last output I posted I noticed that this app is using a terribly old version of wicked_pdf. I updated and it works.
Thanks!
For reference, what version of wicked_pdf, wkhtmltopdf, and rails were you running that caused the issues? I'd like to check if there's perhaps a compatibility issue.
|gem|version|
|-|-|
|Ruby|2.2.4|
|Rails|4.0.13|
|wicked_pdf|0.10.2|
|wkhtmltopdf-binary|0.9.9.1|
But it's working on the heroku production server with those same values -- I don't know if maybe we have something else that's different there or what.
Who wants to use Linux Alpine, should install wkhtmltopdf by apk add wkhtmltopdf command
Most helpful comment
That error message comes from this line, meaning it somehow created a PDF, but the file was empty.
A few things I might check to debug this:
Does executing
wkhtmltopdfon the command-line work for you?/Users/nhinchey/.rvm/gems/ruby-2.2.4/bin/wkhtmltopdf https://google.com google.pdfDoes a simpler
htmldocument work for you in the Rails console?raw_pdf = WickedPdf.new.pdf_from_string('<!doctype html><html><head><title>Hello</title></head><body><h1>Hello, world!</h1></body></html>')Is the directory the tempfiles are written to and read from have permission to write and save files from your app?
If all else fails, you can
gem install pryandbundle open wicked_pdf, and drop arequire 'pry'; binding.pryaround this line, restart your rails server (to pick up the change in the gem source), then when you hit pry's debugging breakpoint inspect the contents of the html tempfiles in thecommandto see if they have issues.You can also execute the command from the command-line yourself here.
Don't forget to remove the
require 'pry'; binding.pryline when you are done, or you canbundle pristine wicked_pdfif you tried making other edits, to re-download and reinstall the gem to overwrite any edits you might have made.Please let me know how it goes and report your findings, if any!