Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

515
Views
Property 'toDataURL' does not exist on type 'HTMLElement'

Hi I am new to TypeScript. I am trying to generate bar code in canvas using JSBarcode and add it to JSpdf as image using addImage. But I am getting the above error.

barcode.html

This is my html code. By click the generate button it has created the barcode. But when I convert my html to PDF it gives the above error.

<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);
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cast it to HTMLCanvasElement:

let canvas = document.getElementById('barcode') as HTMLCanvasElement;

If you are using TypeScript version < 1.6:

let canvas = <HTMLCanvasElement> document.getElementById('barcode');

Now you will have access to toDataURL method.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!