jsPDF输出所有唯一的屏幕截图,而不是打印整个内容

问题描述 投票:-2回答:1

我已经使用jsPDF npm模块在我的角度应用程序中将HTML转换为pdf。但是我注意到将网页打印到PDF只会截取Firefox和Chrome中的可见区域以及Internet Explorer中的可见区域的屏幕截图。但我想将整个网页转换为PDF。

我做了如下:

HTML代码:

<div id="elemetToPrint">
   <!-- lengthy Code here (which is scrollable and contains graph as well)-->
<button class="printBtn" (click)="downloadPDF()">print</button>
</div>

打字稿代码如下:

const doc = new jsPDF({});
const elementToPrint = document.getElementById('elemetToPrint');
doc.addHTML(elementToPrint, () => {
  doc.autoPrint();
  doc.save('Test.pdf');
});

如果有人有解决方案,请告诉我。

你可以找到更多参考here

先感谢您 :)

javascript angular npm jspdf
1个回答
1
投票

看看html2canvas。这将拍摄你的html,然后用jsPDF用html2canvas中的图片创建一个pdf。这个工具与jsPDF密切配合。

https://html2canvas.hertzen.com/

在ANGULAR

 html2canvas(document.querySelector("#capture")).then(canvas => {
        document.body.appendChild(canvas)
  });

HTML

<div id="capture" style="padding: 10px; background: #f5da55">
    <h4 style="color: #000; ">Hello world!</h4>
</div>

教程http://www.shanegibney.com/shanegibney/angular2-and-jspdf-file-generation/

© www.soinside.com 2019 - 2024. All rights reserved.