If you try to run PDFKit on Heroku you will run into a problem with starting a request to the stylesheets from within a request - thin can’t handle that.
Instead of running the PDFKit middleware, you’ll need to add a pdf format in your respond_to block.
First, register PDF as a mime-type in config/initializers/mime_types.rb:
Mime::Type.register "application/pdf", :pdf
Next, create the responder. The trick is to render the view you want to use to a string, create a PDFKit object from that, and add stylesheet paths instead of loading them through the problematic separate request.
format.pdf do kit = PDFKit.new(render_to_string(:template => "controller/view.html", :layout => "layout.html")) # stylesheets in tmp because I'm using compass kit.stylesheets << Rails.root.join('tmp', 'stylesheets', 'style.css').to_s render :text => kit.to_pdf end
Next, you need to make sure that all partials are called as render :partial => 'partial.html' since render_to_string doesn’t know the proper format then.