Try WickedPDF,PDF生成器(來自HTML)插件。
這裏是例子
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
#wicked_pdf is a wrapper for wkhtmltopdf, you'll need to install that, too
在你的控制器(我猜想你是在表演方法):
respond_to do |format|
format.html
format.pdf do
pdf = render_to_string :pdf => 'test',
layout: 'pdf.html.erb',
template: 'show.pdf.slim',
header: { :right => '[page] of [topage]'},
margin: {top: 0,
bottom: 0,
left: 0,
right: 0},
outline: {outline: true,
outline_depth: 2}
end
end
在您的PDF鏈接
= link_to 'Download Pdf', you_show_path(@uour_object, format: :pdf)
如果你想查看在電子郵件附件中發送pdf,首先將您的pdf文件保存在公共或臨時文件夾中,然後在郵件程序類中(例如在郵件程序/ e _mailer.rb)
attachments["test.pdf"] = File.read(Rails.root.join('public',"test.pdf"))
mail(:to => to, :cc => cc , :subject => "subject")
發送電子郵件後,您可以刪除文件
File.delete(Rails.root.join("public", "test.pdf"))
https://github.com/itkin/proselytism.git – nicolas 2013-03-06 08:14:27
那麼,爲什麼你downvote HTMLDOC呢? – 2014-12-17 22:42:17