Question

I've done hours of research trying to get PDFKit to work in my production environment. Everything works fine in development, and "kind of" works on my production server.

  • I'm running 64bit Ubuntu server with Nginx/Passenger.
  • I can successfully create a pdf from my web root using wkhtmltopdf google.com public/test5.pdf -- so I know that wkhtmltopdf is installed and working
  • I can successfully create a PDF using PDFKit using rails console where i can run kit = PDFKit.new('http://google.com') then file = kit.to_file('public/test.pdf') -- so at least in rails console I know that PDFKit is able to run successfully

But, this just isn't working on the actual website. When I visit the URL (which works in development mode) http://staging.myapp.com/tours/5/print_tour.pdf I get the "We're sorry but something went wrong" error. My Passenger error log only shows this:

  • Rack: /home/deploy/myapp/current: No such file or directory - bundle exec which wkhtmltopdf
  • But, I can run bundle exec which wkhtmltopdf fine from my web root?

I'm stumped as wkhtmltopdf runs fine from the command line, as does PDFKit in rails console, but somehow something breaks when serving the page from Nginx/Passenger. Help! :-)

Was it helpful?

Solution

What path does which wkhtmltopdf return and is it different than the path in your development environment?

PDFkit expects wkhtmlpdf to be in /usr/local/bin so if you haven't installed the wkhtmlpdf binary to that location, make sure you specified the path in an initializer like so:

# config/initializers/pdfkit.rb
PDFKit.configure do |config|
  config.wkhtmltopdf = '/path/to/wkhtmltopdf'
  # config.root_url = "http://staging.myapp.com" # Use only if your external hostname is unavailable on the server.
end

If your problem isn't related to PDFkit trying to call wkhtmltopdf from the wrong path on the server, have you tried seeing if another gem like wicked_pdf is able to use wkhtmltopdf properly?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top