[英]Property 'toDataURL' does not exist on type 'HTMLElement'
Hi I am new to TypeScript. 嗨,我是TypeScript的新手。 I am trying to generate bar code in canvas using JSBarcode and add it to JSpdf as image using
addImage
. 我试图生成使用JSBarcode帆布条形码,并用它添加到JSpdf作为图像
addImage
。 But I am getting the above error. 但我得到了上述错误。
This is my html code. 这是我的HTML代码。 By click the generate button it has created the barcode.
通过单击生成按钮,它已创建条形码。 But when I convert my html to PDF it gives the above error.
但是当我将我的html转换为PDF时,它会出现上述错误。
<canvas id="barcode"></canvas>
<a id="download" download="barcode.png" (click)='Generate();'>Generate</a>
<button (click)='Generatepdf();'>PDF</button>
private Generate(): void {
JsBarcode("#barcode", "12345", {
width: 2,
height: 25
});
}
Generatepdf()
{
var pdf = new jsPDF('p', 'pt', 'letter');
let canvas =document.getElementById('barcode');
console.log(canvas);
let dataURL = canvas.toDataURL("image/jpeg");
pdf.addImage(dataURL, 'JPEG', 15, 40, 180, 160);
function (dispose) {
pdf.output('datauri');
}, margins);
}
Cast it to HTMLCanvasElement
: 将其
HTMLCanvasElement
为HTMLCanvasElement
:
let canvas = document.getElementById('barcode') as HTMLCanvasElement;
If you are using TypeScript version < 1.6: 如果您使用的是TypeScript版本<1.6:
let canvas = <HTMLCanvasElement> document.getElementById('barcode');
Now you will have access to toDataURL
method. 现在您将可以访问
toDataURL
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.