温馨提示:本文翻译自stackoverflow.com,查看原文请点击:javascript - Angulr 6 dom-to-image throws uncaught error (Can't convert html to image)
angular javascript image wkhtmltoimage

javascript - Angulr 6 dom-to-image引发未捕获的错误(无法将html转换为图像)

发布于 2020-03-27 15:35:03

我想将html部分转换为图像(注意 html部分还有来自服务器的许多其他图像)我正在使用angular 6和node.js,将html转换为图像的库是 dom-to-img

它在localhost中工作,但是当我将其测试到生产级别时,它给我错误那是图片 错误

这是我要转换为图像的HTML区域,其中来自服务器的签名和背景色为URL

HTML区域

我使用了 @ViewChild('checkContainer')容器;获取dom(Html部分)引用,然后调用一个给我图像类型文件的函数,然后传递给将该图像保存在数据库中的服务器。 所有人都在Localhost中工作,但不在生产中

这是我尝试过的代码。

async convertToImage(fileName) {
try {
  const blob = await domtoimage.toBlob(this.container.nativeElement);
   this.checkImageFile = new File([blob], fileName + '.png', {
     type: 'image/png'
   }); // image File
} catch (error) {
  console.log('ops error', error);
}

}

以上函数将从此函数调用checkImageFile是在文件中声明的属性名称。

async addCheck() {
const fileName = this.checkModel.checkNumber;
await this.convertToImage(fileName);
if (this.checkImageFile) {
  console.log(this.checkImageFile);
} else {
  console.log('dom to image is not working properly');
}

}

我的代码中缺少什么?你能帮我么?谢谢大家快乐编码。

查看更多

查看更多

提问者
Tanzeel Saleem
被浏览
58
Tawfiek Khalaf 2019-07-04 00:00

该软件包存在兼容性问题,您可以使用以下软件包代替dom-to-image-more