Q:

Convert html string to pdf with prawnto

I have field which stores html content. I want to convert html strings in the pdf. I am using prawnto to generate pdf.
Any idea ? How to convert specific html string to pdf string ?

A:

It's easy with PDFKit:
@your_object = YourObject.find(params[:id])
respond_to do |format|
  format.pdf do
    #html = render_to_string(:action => "show.html.haml", :layout => "pdf.html.haml")
    html = @your_object.your_html_field
    content = PDFKit.new(html)
    send_data(content.to_pdf, :filename => "content.pdf", :type => 'application/pdf', :disposition => 'inline')
  end
end

It uses wkhtmltopdf in a background and it's pretty easy to install too. It has a lot of options allowing to customize a pdf generation.
Ryan Bates has a screencast on it.

