Cannot get wicked_pdf to work on heroku ? (but it works locally)
Following the guide on https://github.com/jordan-brough/heroku-pdf I managed to have wicked_pdf working locally and creating PDF as expected. However once I push to heroku, the app crashes after a while everytime I call the pdf
The logs gives me this:
2011-05-19T06:36:56+00:00 app[web.1]: Started GET "/authors/cash_payment_receipt/4dd4aff0a2d5a5000100000c.pdf" for XXX.XXX.XXX.XXX at Wed May 18 23:36:56 -0700 2011
2011-05-19T06:36:56+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET xxx.xxxx.com/authors/cash_payment_receipt/4dd4aff0a2d5a5000100000c.pdf dyno=web.1 queue=0 wait=0ms service=0ms bytes=0
2011-05-19T06:36:56+00:00 app[web.1]: !! Unexpected error while processing request: PDF could not be generated!
2011-05-19T06:36:56+00:00 app[web.1]: /app/.bundle/gems/ruby/1.8/gems/wkhtmltopdf-0.1.2/bin/wkhtmltopdf_linux_386: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory
I added the wkhtmltopdf bin to my rails-root/bin directory, checked the rights, and it's all ok. I first tried the 0.10rc2 and moved back down to 0.9.9 but it all gives the same results.
I can't fi开发者_如何学Gond anything on google related to my error. I don't see what I am doing wrong.
The env is: - rails 3.0.7 - ruby 1.8.7
Thanks,
Ale
I recently created a GEM for the wkhtmltopdf binaries to work on heroku without you having to install any binaries in your own repository. It also comes packed with the OSX ( darwin ) binary for development. It worked with PDFKit and probably should work with WickedPDF as well
https://github.com/bradphelan/wkhtmltopdf-heroku
or in your Gemfile as
gem "wkhtmltopdf-heroku"
this github project was immensely helpful for me, I have it running in rails 3 projects thanks to this
I was able to follow the steps described here https://github.com/jordan-brough/heroku-pdf to make my own copy of the project and it worked fine locally and on heroku.
I then updated the application to work with rails 3.0.9. It is running on heroku http://heroku-pdf-3.heroku.com/. You can grab my code from here for this project.
For the record, I've experienced where this works perfectly on our stage env (same heroku setup), but a deploy to production can break with the error above (but not always).
When this happens, a re-deploy worked (no idea why). Since it's a git repo, you'll have to make a minor change, otherwise it won't allow you to push again.
The wicked_pdf uses wkhtmltopdf
to convert HTML to PDF (as the name obviously states). You can download its binary here, and place it in your apps bin
folder.
You also need to create a wicked_pdf.rb
initializer pointing to the binary:
# config/initializers/wicked_pdf.rb
WickedPdf.config = {
:exe_path => Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s,
}
However, if you need to input images into your PDF files, you'll need a X server running. Since you can't run a X server in Heroku, there are two ways out:
- Use
xvfb
to wrap your wkhtmltopdf binary within a virtual X server environment - Install a HTML to PDF provider in another server, where you have more flexibility, such as a VPS in RackSpace or Amazon EC2.
I prefer the second option, since it detachs PDF creation in another server and does not compromises the rest of the application with performance issues.
You can see how to do that here: http://blog.hugerepo.com/2013/04/29/how-to-create-your-own-html-to-pdf-provider/
I had the same problem. I fixed it by using the amd64 build of wkhtmltopdf binary instead of the i386.
精彩评论