0
我有存储html内容的字段。我想在PDF中转换html字符串。我正在使用prawnto生成pdf。将html字符串转换为pdf与prawnto
有什么想法?如何将特定的html字符串转换为pdf字符串?
我有存储html内容的字段。我想在PDF中转换html字符串。我正在使用prawnto生成pdf。将html字符串转换为pdf与prawnto
有什么想法?如何将特定的html字符串转换为pdf字符串?
这很容易与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
它在后台使用wkhtmltopdf,它是很容易install了。它有很多选项可以定制一代pdf。
瑞安贝茨有一个screencast就可以了。