wicked_pdf ,测试在jruby下也可用。点击打开链接
# create a pdf from a string
pdf = WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
# create a pdf from string using templates, layouts and content option for header or footer
WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "pdf_file.pdf", :template => 'templates/pdf.html.erb', :layout => 'pdfs/layout_pdf'),
:footer => {:content => render_to_string({:template => 'templates/pdf_footer.html.erb', :layout => 'pdfs/layout_pdf'})}
# or from your controller, using views & templates and all wicked_pdf options as normal
pdf = render_to_string :pdf => "some_file_name"
# then save to a file
save_path = Rails.root.join('pdfs','filename.pdf')
File.open(save_path, 'wb') do |file|
file << pdf
end
再有就是pdfkit这个gem,整体原理与上述gem类似,都调用wkhtmltopdf。
wkhtmltopdf地址:http://code.google.com/p/wkhtmltopdf/,对照系统下载安装即可。
本文详细介绍了如何在 JRuby 环境下使用 WickedPdf 和 pdfkit gem 创建 PDF 文档,包括从字符串创建 PDF、使用模板和布局创建 PDF、从控制器中创建 PDF 并保存到文件的方法。
698

被折叠的 条评论
为什么被折叠?



