前端学习笔记:angular4中将html导出为pdf
2018-04-24 22:50
447 查看
angular5中将html导出为pdf
1.安装pdfmake:
[code]npm install pdfmake --save
2.在ts文件中导入:
[code]import * as pdfMake from 'pdfmake/build/pdfmake'; import * as pdfFonts from 'pdfmake/build/vfs_fonts';
3.测试pdfmake:
[code]pdfMake.vfs = pdfFonts.pdfMake.vfs; var dd = { content:{text:"HelloWorld!",alignment: 'center',}; pdfMake.createPdf(dd).download();
4.处理中文问题:
a.找到需要的字体文件(后缀.ttf);
b.将pdfmake的源代码克隆或下载到本地,(https://github.com/bpampuch/pdfmake);
c.进入pdfmake根目录,安装gulp,使用命令为
[code]npm install gulp --save-dev;
d.安装pdfmake所需要的依赖包,使用命令:
[code]npm install;
e.将自己所需要的字体放在pdfmake目录下的examples/fonts的目录中;
f.然后在执行:
[code]gulp buildFonts ;
g.f步骤完成后会在build 文件夹中找到vfs_fonts.js
h.用pdfmake项目中的vfs_fonts.js替换原来项目中的vfs_fonts.js
5.使用字体:(以“微软雅黑”为例)
[code]pdfMake.fonts = { 微软雅黑: { normal: '微软雅黑.ttf', bold: '微软雅黑.ttf', italics: '微软雅黑.ttf', bolditalics: '微软雅黑.ttf', } }; var dd = { content:{text:"HelloWorld!",alignment: 'center',font: '微软雅黑'}; pdfMake.createPdf(dd).download();
6.其他操作可以参考官网
阅读更多
相关文章推荐
- JasperReport学习笔记7-导出成其它格式(pdf,xls,html)
- JasperReport学习笔记7-导出成其它格式(pdf,xls,html)
- JasperReport学习笔记7-导出成其它格式(pdf,xls,html)
- JasperReport学习笔记7-导出成其它格式(pdf,xls,html)
- WEB前端学习笔记-HTML(上)
- OAF学习笔记-23-OAF中将数据库中的表导出生成xls ,xlsx,csv 等格式
- 前端学习笔记--HTML/CSS--网页布局
- 前端HTML、CSS学习完整笔记(中上篇)
- 前端学习笔记之Html标签元素类别
- 前端学习笔记-HTML(二)
- OAF学习笔记-23-OAF中将数据库中的表导出生成xls ,xlsx,csv 等格式
- 前端开发学习笔记(三)HeadFirst HTML 与 CSS (第二版)
- Web 前端学习笔记之 HTML 入门(1)
- 〖前端开发〗HTML/CSS基础知识学习笔记
- 前端开发学习笔记02----HTML基础
- OAF学习笔记-23-OAF中将数据库中的表导出生成xls ,xlsx,csv 等格式
- 前端学习笔记1---HTML meta简介、JavaScript简介创建对象--待完善
- WEB前端学习笔记-HTML(中)
- WEB前端学习笔记-HTML(下)
- 【网页前端学习之html】 学习笔记1-入门(开发工具)