html - html2canvas:错误未捕获(承诺):[object undefined] angular 6
问题描述
我正在使用 html2canvas 将 html 转换为图像,然后导出为 pdf 文件。这是我使用这个包的步骤:
纱线添加 html2canvas
添加代码以将 html 转换为图像。
async export(comp, doc, save) { // create pdf file let height = REPORT_PAGE.top; const header = comp.reportHeader.nativeElement; const headerCanvas = await html2canvas(header, {svgRendering: true}); height = REPORT_PAGE.top; let imgHeightHtml = REPORT_PAGE.header * REPORT_PAGE.width / headerCanvas.width; let contentDataURL = headerCanvas.toDataURL('image/png'); doc.addImage(contentDataURL, 'PNG', REPORT_PAGE.left, height, REPORT_PAGE.width, imgHeightHtml); if (save) { doc.save('myreport.pdf'); } else { doc.addPage(); } }
其中 comp 是角度分量,doc 是 jsPDF,save 是布尔值。调用 html2canvas 时会抛出以下错误。
Uncaught (in promise): [object Undefined]
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4053)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (zone.js:500)
at ZoneTask.invoke (zone.js:485)
html2canvas 是一个非常有用的包,但是这个错误真的很糟糕。请帮忙。
解决方案
我有同样的问题,这解决了它:
html2canvas(element, {
ignoreElements: (node) => {
return node.nodeName === 'IFRAME';
}
}).then((canvas) => {
...
});
来源:https ://github.com/niklasvh/html2canvas/issues/1593#issuecomment-489059452
推荐阅读
- amazon-web-services - 将 www 流量重定向到 nginx AWS Elastic Beanstalk 中的非 www
- wordpress - 将外部 URL 添加到 WordPress 的 WooCommerce 类别
- awk - 使用 awk 填充文件
- php - 如何使这个简单的表单正常运行?
- python - 如何更改 Matplotlib 3d 绘图中的边框颜色?
- javascript - 如果我链接我的 CSS,我网站内的谷歌地图不起作用
- bash - 为什么“set VAR=value”在 bash 中不起作用?
- nativescript - 使用 NativeScript 读取设备的接近传感器
- jquery - 使用自定义复选框 CSS 的 jQuery 验证在表单验证后不起作用
- bpmn - 启用以取消进程直到它完成