0

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! :-)

FireDragon
  • 9,325
  • 4
  • 27
  • 34
  • I've installed wkhtmltopdf using steps similar to this--it installs fine but doesn't fix the issue I have. http://wingdspur.com/2012/12/installing-wkhtmltopdf-on-ubuntu/ – FireDragon Jul 25 '13 at 21:02
  • `wkhtmltopdf` started under `xvfb` mode right – Viren Jul 30 '13 at 19:33
  • @Viren I'm unsure how to tell if it's being run in xvfb mode? Do you know how I can tell? And what this means as far as running wkhtmltopdf? What I can say is that wkhtmltopdf runs fine from the command line when in the root rails directory. thanks! – FireDragon Aug 01 '13 at 21:32

1 Answers1

1

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?

  • I got this working and not sure what exactly what was going on. The problem was that there were several issues so it was confusing to decipher. First, @wingdspur, for some reason my installation is using 'usr/bin/wkhtmltopdf` instead of `/usr/local/bin/wkhtmltopdf` but i just created a simlink so the "real" executable is in usr/local. Second, even when the executable was found I needed to apply an override by creating an initializer file--follow this link for details: https://github.com/pdfkit/pdfkit/issues/82 . Third was that I needed to look at the correct log files in /log/ dir to see error – FireDragon Aug 02 '13 at 02:27