首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用prawnto将html字符串转换为pdf

使用prawnto将html字符串转换为pdf
EN

Stack Overflow用户
提问于 2011-05-16 22:06:11
回答 1查看 819关注 0票数 0

我有存储html内容的字段。我想在pdf中转换html字符串。我正在使用prawnto生成pdf。

有什么想法吗?如何将特定的html字符串转换为pdf字符串?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-16 22:23:06

使用PDFKit很容易

代码语言:javascript
复制
@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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6018621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档