mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 646 forks source link

wicked PDF gem gives Error and do not genearte the pdf #439

Open timasingh opened 9 years ago

timasingh commented 9 years ago

Hi all

I am using wicked PDF gem version 0.9 for generating HTML to PDF , We have seen massive numbers of errors in all our environment , where PDF is not generated and throws the below error Also i can confirm this happens only in 20 % of the cases, we have a ticket booking system so out of 100 tickets being booked there may be ~10/20 incidences when ticket is not being generated and we get the error

Errror:

A RuntimeError occurred in background at 2015-08-20 20:35:59 +0100 : Failed to execute: “/usr/local/bin/wkhtmltopdf” -q "file:////tmp/wicked_pdf20150820-22625-1ydsjt2.html" “/tmp/wicked_pdf_generated_file20150820-22625-ebglcw.pdf” Error: PDF could not be generated! Command Error: xvfb-run -a -s “-screen 0, 1024x768x24” wkhtmltopdf.bin $* + xvfb-run -a -s ‘-screen 0, 1024x768x24’ wkhtmltopdf.bin -q file:////tmp/wicked_pdf20150820-22625-1ydsjt2.html /tmp/wicked_pdf_generated_file20150820-22625-ebglcw.pdf

/var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/wicked_pdf-0.9.10/lib/wicked_pdf.rb:79:in `rescue in pdf_from_string'

Backtrace: /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/wicked_pdf-0.9.10/lib/wicked_pdf.rb:79:in rescue in pdf_from_string' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/wicked_pdf-0.9.10/lib/wicked_pdf.rb:83:inpdf_from_string' /var/application/nus/nusdigital/app/mailers/event_booking_mailer.rb:38:in notify_event_booking' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:167:inprocess_action' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in process' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:inprocess' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:459:in process' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:453:ininitialize' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque_mailer-2.2.4/lib/resque_mailer.rb:48:in new' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque_mailer-2.2.4/lib/resque_mailer.rb:48:inperform' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/job.rb:240:in block (3 levels) in perform' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.9.0.229/lib/new_relic/agent/instrumentation/resque.rb:40:inblock in around_perform_with_monitoring' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.9.0.229/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:364:in perform_action_with_newrelic_trace' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.9.0.229/lib/new_relic/agent/instrumentation/resque.rb:34:inaround_perform_with_monitoring' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/job.rb:239:in block (2 levels) in perform' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/job.rb:247:incall' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/job.rb:247:in perform' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/worker.rb:250:inperform' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/worker.rb:189:in block in work' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/worker.rb:166:inloop' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/worker.rb:166:in work' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/resque-1.25.0/lib/resque/tasks.rb:41:inblock (2 levels) in ' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:228:in call' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:228:inblock in execute' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:223:in each' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:223:inexecute' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:166:in block in invoke_with_call_chain' /usr/lib/ruby/1.9.1/monitor.rb:201:inmon_synchronize' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:159:in invoke_with_call_chain' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:152:ininvoke' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:143:in invoke_task' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:101:inblock (2 levels) in top_level' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:101:in each' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:101:inblock in top_level' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:110:in run_with_threads' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:95:intop_level' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:73:in block in run' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:160:instandard_exception_handling' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:70:in run' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/bin/rake:37:in' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/bin/rake:23:in load' /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/bin/rake:23:in' ------------------------------- Data:

unixmonkey commented 9 years ago

You are hitting the rescue on this line:

https://github.com/mileszs/wicked_pdf/blob/0.9.10/lib/wicked_pdf.rb#L78

You could open the gem source file (at /var/application/nus/nusdigital/vendor/bundle/ruby/1.9.1/gems/wicked_pdf-0.9.10/lib/wicked_pdf.rb), and try commenting out lines 78 and 79, reproduce the issue, and see what exception is actually being raised to give you a clue to what is happening in your setup.

I see you are generating the pdfs in a worker job through Resque. If one job begins before the other is finished, wkthmtopdf will try to spawn Xvfb on the same display, which will fail if you already have one running.

You might need to specify the --auto-servernum --server-num=1 parameters to xvfb-run. I see you already have the shorthand argument, -a, but I've seen reported success by specifying the --server-num=1.

You could also try upgrading wicked_pdf. 0.11.0 is the latest official release, however many people have been running against master, which works better with newer releases of wkhtmltopdf (that are not backward compatible in syntax).

You can run against master by adding this to your Gemfile in place of your existing wicked_pdf and wkhtmltopdf gems:

gem 'wicked_pdf', github: 'mileszs/wicked_pdf'
gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'

Let me know how it goes!

shanmugavela commented 9 years ago

Thanks.

We have specified the number of worker as 1 and commented 78 and 79 lines. Still we could not able to reproduce the issue in lower environments.

we have upgraded the wicked_pdf gem alone. we are using centos so omitted gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1' .

Will let you the outcome of upgrade.

akhilyadav002 commented 4 years ago

Any updates on this? I am using the following versions, and also getting the exact same error mentioned here. wicked_pdf (1.4.0) wkhtmltopdf-binary (0.12.4)

juliofalbo commented 3 years ago

Any news? Facing the same issue.