gpt4 book ai didi

html2canvas:未捕获错误( promise ):[对象未定义] angular 6

转载 作者:行者123 更新时间:2023-12-04 17:40:21 26 4
gpt4 key购买 nike

我正在使用 html2canvas 将 html 转换为图像,然后导出为 pdf 文件。这是我使用这个包的步骤:

  1. yarn 添加html2canvas

  2. 添加代码以将 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 是 bool 值。调用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

关于html2canvas:未捕获错误( promise ):[对象未定义] angular 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52617417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com