【发布时间】:2019-11-17 14:20:25
【问题描述】:
当我运行应用程序并单击按钮时,PDF 看起来是空的。
我正在寻找 console.log(),但画布没有显示任何内容。
import { Component, OnInit } from '@angular/core';
import * as jspdf from 'jspdf';
import html2canvas from 'html2canvas';
generatePDF(){
html2canvas(document.getElementById('albaran')).then(canvas => {
// Few necessary setting options
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', 'a4'); // A4 size page of PDF
var position = 0;
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight)
pdf.save('MYPdf.pdf'); // Generated PDF
});
}
}
【问题讨论】:
-
应该是html2canvas的版本。看看这个答案是否有帮助:stackoverflow.com/a/56481588/4271117
标签: angular7 ionic4 jspdf html2canvas