I am using the WickedPDF gem and wkhtmltopdf to generate PDF files from my application. It all works fine on my development machine, but fails when I deploy to production on Heroku. The error I get is:
“RuntimeError (Location of wkhtmltopdf unknown):”
which is generated by the gem.
I’ve added the executable to my /app/bin directory but it’s not there when I deploy.
So there’s a couple of things you’ll need to get right - the architecture for the binary and the path. I assume you’ve checked in an executable that works on heroku’s flavor of linux (you want a statically linked 64-bit version of wkhtmltopdf). For the path, you should just need to set it for WickedPDF, thusly:
Assuming you checked it into a “bin/” directory in the root of your rails project.
If you’re not developing on a 64-bit linux, you’d change the path to wkhtmltopdf depending on the value of Rails.env or perhaps an environment variable, then you can use different versions (osx for development, 64-bit for heroku) in different places.
I thought I had done all those things correctly (my development machine is Kubuntu 64-bit), but I had put the wkhtmltopdf executable into the wrong location. Moving it to where you suggested did the trick ('m guessing that my development stack worked because it was able to find the executable elsewhere in my PATH).
One interesting thing is that even if I enter
Dir.entries “#{Rails.root}/bin”
at the consolle, wkhtmltopdf doesn’t show up there, but at least it works now.
I know; but I wanted the latest version of wkhtmltopdf and that gem hadn’t been updated for a year. I didn’t want a back-level version – I think it was 0.9.9.1 and the latest is 0.11.0.rc1.
Good point; I just submitted a pull request for the wkhtmltopdf-heroku gem. It purports to automagically support WidkedPDF, PDFKit, and wisepdf, depending on which one is loaded. When I started looking at the wkhtmltopdf-binary “family” of gems, it was pretty involved: steerio/wkhtmltopdf-binary (the one I originally looked at), is forked from unixmonkey/wkhtmltopdf_binary_gem which in turn is forked from michaelcollas/wkhtmltopdf_binary_gem, which is itself forked from zakird/wkhtmltopdf_binary_gem and who knows how many forks on other legs…
That’s not something I’m inclined to sign up for! And given the simplicity of adding the single binary in my app (now that I know how to do that), I’m inclined to keep it that way and avoid any of those gems entirely. In fact, I’m beginning to come to the conclusion that it may be better in the long run to install things manually for what I’ll call “minor” gem functionality such as this one: I know mor of what’s going on and have more control over the final outcome.