我有存储html内容的字段。我想在pdf中转换html字符串。我正在使用prawnto生成pdf。
有什么想法吗?如何将特定的html字符串转换为pdf字符串?
发布于 2011-05-16 22:23:06
使用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
https://stackoverflow.com/questions/6018621
复制相似问题