I\'m able to download pdf file with:
curl google.com | wkhtmltopdf - test.pdf
so it means, wkhtmlpdf installation was successful.
B
Setting config.action_controller.asset_host = "http://localhost"
in development.rb actually didn't work for me. That is, the PDF generation would work, but then assets wouldn't come through when rendering HTML.
I followed the method here: http://jguimont.com/post/2627758108/pdfkit-and-its-middleware-on-heroku
and it worked like a charm for me. Hope this helps someone. Just throw assets.rb in config/intializers and you're good to go.
The issue was due to stylesheet_link_tag
and javascript_include_tag
using relative URLs, which often causes wkhtmltopdf
to hang when loading assets from the same server that wkhtmltopdf
is running on.
Using absolute URLs for assets solved the problem.
Set asset_host
in Rails' config, which also affects stylesheet_link_tag
and javascript_include_tag
:
# Modify asset host config setting in `config/application.rb`
# Or create a new initializer: `config/initializers/wkhtmltopdf.rb`
config.action_controller.asset_host = "http://mysite.com"
# Or you can have different hosts for development (local) and production (CDN):
# In `config/environments/development.rb`
config.action_controller.asset_host = "http://localhost"
# In `config/environments/production.rb`
config.action_controller.asset_host = "http://d111111abcdef8.cloudfront.net"
I had the same issue in which my log showed the page had rendered however no pdf was generated and the browser would hang. It ended up having nothing to do with OS compatability, missing librariers, gems nor dependencies but instead I needed to raise the max allowable thread count for my Puma server (which had been set to 1) upto 2 or more. This then generated pdf's as normal.