I need to print an order into PDF. I am using pdfkit gem. Absolutely exhausted but its just not printing any css.
application.html.erb:
<%= stylesheet_link_tag "application", :media => "all"%>
order_controller.rb
respond_to do |format|
format.html
format.pdf {
html = render_to_string(:template => "show.html.erb")
kit = PDFKit.new(html)
kit.stylesheets << "http://localhost:3000/stylesheets/application.css" <-- hardcoded this
send_data(kit.to_pdf, :filename => "test_pdf", :type => "application/pdf", :disposition => 'attachment')
return
}
config/initializers/pdfkit.rb
PDFKit.configure do |config|
config.wkhtmltopdf = 'Gem/Path/to/wkhtmltopdf'
config.default_options = {
:page_size => 'Legal',
:print_media_type => true
}
# Use only if your external hostname is unavailable on the server.
config.root_url = "http://localhost"
config.verbose = false
end
application.rb
config.middleware.use "PDFKit::Middleware", :print_media_type => true
mime_types.rb
Mime::Type.register 'application/pdf', :pdf
I simply go to the page like http://localhost:3000/orders/4 and append a .pdf (as per Railscasts). http://localhost:3000/orders/4.pdf shows a pdf but no css. Same with Browser's print preview.
Does anyone know how I can debug this further?