Hey there! I'm new to TypeScript and I've been experimenting with generating barcodes in a canvas using JSBarcode and then adding it to JSpdf as an image using the addImage
function. However, I keep encountering the error mentioned above.
barcode.html
This is the HTML code snippet I have. When I click the generate button, it successfully creates the barcode. But when I try to convert my HTML to a PDF, that's when the error occurs.
<canvas id="barcode"></canvas>
<a id="download" download="barcode.png" (click)='Generate();'>Generate</a>
<button (click)='Generatepdf();'>PDF</button>
barcode.ts
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);
}