我在从我的页面生成pdf时遇到了问题。我正在使用jspdf和html2canvas,但生成的pdf是白页。请帮助我
HTML:
<mat-card>
<table id="contentToConvert">
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
</tr>
<tr>
<td>Row 1</td>
<td>Row 1</td>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
<td>Row 2</td>
<td>Row 2</td>
</tr>
<tr>
</table>
</mat-card>
Component.ts:
import * as jspdf from 'jspdf';
import html2canvas from 'html2canvas';
.
.
.
public captureScreen() {
var data = document.getElementById('contentToConvert');
html2canvas(data).then(canvas => {
var imgWidth = 208;
var pageHeight = 295;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
const contentDataURL = canvas.toDataURL('image/png')
let pdf = new jspdf('p', 'mm', 'a2'); // A4 size page of PDF
var position = 0;
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight)
pdf.save('MYPdf.pdf'); // Generated PDF
});}
预先感谢。菲利波
@ Prashant Pimpale,我发布了从浏览器中看到的内容: