再见html转pdf

1.在线引入eKoopmans项目的html2pdf js包

1 function addScript(url) {
2     var script = document.createElement('script');
3     script.type = 'application/javascript';
4     script.src = url;
5     document.head.appendChild(script);
6 }
7 addScript('https://raw.githack.com/eKoopmans/html2pdf/master/dist/html2pdf.bundle.js');

2.执行pdf生成脚本

 1 html2pdf(document.getElementById("scrollContainer"),{
 2 pagebreak: {
 3     mode:'css',
 4     after:'.every-index-in-report' 
 5 },
 6 html2canvas:  { 
 7     scale: 2 //暂时解决了导出内容会截断的问题
 8 },
 9 jsPDF:{
10     unit:'px',
11     hotfixes:["px_scaling"],
12     format:[1250, 750],
13     orientation:'l',
14     putOnlyUsedFonts:true
15 }
16 })

pagebreak:分页控制


具体参数含义请参考官方地址

posted @ 2021-08-05 10:28  无色无味  阅读(109)  评论(0编辑  收藏  举报