[Rails] from html to pdf


I'm trying to use the nice library PDFKit, used for generate Pdf given an html in a rails application.

An interesting strategy for retrieving html generated by rails in order to put it directly in your pdf is shown in the following example:












def export_pdf

html = render :layout => false

kit = PDFKit.new(html)

kit.stylesheets << RAILS_ROOT + '/public/stylesheets/your_css.css'

send_data(kit.to_pdf, :filename => "your_pdf_name.pdf", :type => 'application/pdf')


end

Nessun commento: