FireDragon
FireDragon

Reputation: 9385

wkhtmltopdf (with pdfkit) installed on Ubuntu but not working in Rails

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.

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:

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

Upvotes: 0

Views: 6967

Answers (1)

user484608
user484608

Reputation:

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?

Upvotes: 1

Related Questions