2

I'm finishing a PDF report implementation for my application, which works perfectly in development mode, but when uploading to Heroku, it doesn't work, and I get the following error:

2011-10-24T03:28:02+00:00 app[web.1]: RuntimeError (Failed to execute:
2011-10-24T03:28:02+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/bin/wkhtmltopdf --header-html 'file:///app/tmp/wicked_header_pdf_1_0.html' --footer-html 'file:///app/tmp/wicked_footer_pdf_1_0.html'     --orientation 'landscape' --page-size 'A4' --encoding 'UTF-8'   -q - - 
2011-10-24T03:28:02+00:00 app[web.1]: Error: PDF could not be generated!):
2011-10-24T03:28:02+00:00 app[web.1]:   app/controllers/gliders_controller.rb:244:in `block (2 levels) in report'
2011-10-24T03:28:02+00:00 app[web.1]:   app/controllers/gliders_controller.rb:228:in `report'

I've tried adding an initializer and manually uploading the wkhtmltopdf bin file to heroku following the example in this github repository, but I still can't get it to work.

I can't seem to grasp the exact reason why this wouldn't work in Heroku, could anyone give me a hand? Thanks in advance.

bbonamin
  • 30,042
  • 7
  • 40
  • 49

3 Answers3

2

I got it to work. After a little searching, I found a github repo that implements a wicked_pdf initializer that works with Rails 3 and Heroku.

To make this work in your app:

  1. Copy the bin directory to the root of your application
  2. Copy the wickedpdf.rb into your config/initializers directory so that you get the same errors from heroku
  3. Copy the "config.after_initialize do" statement from development.rb so that your local binary is found in development.
Community
  • 1
  • 1
bbonamin
  • 30,042
  • 7
  • 40
  • 49
0

Using the wkhtmltopdf-binary gem will make wicked_pdf work in all environments. This takes away the need to manually install wkhtmltopdf on your local machine or on any production server.

gem install wkhtmltopdf-binary

Alex
  • 1,618
  • 1
  • 17
  • 25
0

Heroku is a read-only filesystem and you're attempting to create a new file on that system. You cannot do this.

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • Hey Ryan, check my answer, I got it to work!. I was not trying to write to heroku's filesystem, as I'm showing the pdf to the user in a respond_to block. Thanks for your answer anyway! – bbonamin Oct 24 '11 at 03:44
  • Things have changed slightly these days - tmp has always been writable on Heroku whilst on the Cedar stack it's entirely writable just not persisted across dynos. – John Beynon Oct 24 '11 at 08:03