rails实现PDF文档导出功能
2018-01-10 20:20
459 查看
业务系统中,经常有导出PDF的需求,现使用
将自己需要的字体拷贝至
目前的需求很简单,只需要将文字内容转化成pdf:
现在想实现这样的一个功能:将
定义路由:
代码实现:
prawn来实现这一功能。
gem install prawn;
bundle exec rake manual生成manual.pdf帮助文档;
将自己需要的字体拷贝至
"#{Prawn::DATADIR}/fonts/"路径下;
目前的需求很简单,只需要将文字内容转化成pdf:
def generate_pdf(content) Prawn::Document.generate("test.pdf") do file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf" font_families["Kai"] = { :normal => { :file => file, :font => "Kai" } } text content, :fallback_fonts => ["Times-Roman", "Kai"] end end
现在想实现这样的一个功能:将
markdown编写个人简历导出成
prawn无法转化
html格式,因此放弃使用,选择
pdfkit。
Gemfile中添加
gem 'pdfkit'和
gem 'wkhtmltopdf-binary',然后执行
bundle install;
定义路由:
get 'download', to: 'welcome#download_resume'
代码实现:
# app/controllers/welcome_controller.rb def download_resume resume = current_user.resume content = resume.content_html.nil? ? resume.content : resume.content_html kit = PDFKit.new(content, page_size: 'Letter') pdf = kit.to_pdf file_name = "#{current_user.username}的个人简历.pdf" send_data(pdf, filename: file_name) end
相关文章推荐
- Java实现office文档与pdf文档的在线预览功能
- JQuery Plugin-TableExport实现前端表格的导出功能(已解决表格pdf导出中文格式问题)
- java零碎要点010---Java实现office文档与pdf文档的在线预览功能
- 水晶报表导出为pdf, word , excel 格式(已经测试过,实现了该功能)
- 通用的web系统数据导出功能设计实现(导出excel2003/2007 word pdf zip等)
- ThinkPHP 整合 PHPExcel ,数据导出功能实现,解决Invalid cell coordinate PHPExcel想必大家都不陌生,是用来操作Office Excel 文档的一个PHP
- Ubuntu 服务器 PHP实现word、excel、ppt、pdf 等文档在线阅读功能的实现
- java 实现导出pdf文档
- vue实现word,pdf文件的导出功能
- 使用Lucene对doc、docx、pdf、txt文档进行全文检索功能的实现
- Java实现office文档与pdf文档的在线预览功能
- JQuery Plugin-TableExport实现前端表格的导出功能(已解决表格pdf导出中文格式问题)
- 具有强大构建强大的Word报表,支持XAML数据绑定,文档格式转换,导出为PDF等功能的控件TX Text Control .NET for WPF介绍
- 使用jfreechart和itext实现导出报表和表格到pdf文档
- Java 实现 FusionCharts 图表导出图片或PDF文件功能
- 关于论坛实现pdf,word等文档在线预览的功能探讨
- Apache-POI实现Excel文档的导出下载功能
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
- Java实现office文档与pdf文档的在线预览功能
- php实现pdf导出和打印功能。