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

80
Views
html to image for more than 100 divs fails

I am using html-to-image library to convert div element to image, which is working fine for single div, but if i use it for divs in for loop then it breaks

    <div *ngFor="let template of templates; index as i">
      <div id="{{template.templateName}}_front_{{i}}" [innerHTML]="(template.templateHtmlFront) | safeHtml">
      </div>
      <div id="{{template.templateName}}_back_{{i}}"
        [innerHTML]="(template.templateHtmlBack) | safeHtml"></div>
    </div>

I want to convert each front and back template in an image. so i have written following code in ts file

async createFiles() {
const imageData: any[] = [];
for (let tempIdx = 0; tempIdx < this.templates.length; tempIdx++) {
 
  const containerFront = document.getElementById(`${template.templateName}_front_${tempIdx}`);
 
  //save front template
  if (containerFront) {
    await htmlToImage.toJpeg(containerFront)
      .then((dataUrl) => {
        const imageName = `${template.templateId}_front.jpeg`;
        const imageBlob: Blob = this.service.dataURItoBlob(dataUrl);
        const imageFile = new File([imageBlob], imageName, { type: 'image/jpeg' });
        imageData.push(imageFile);
      }).catch(function (error) {
        console.error('oops, something went wrong!', error);
      });
  }
  //Save back
    const containerBack = document.getElementById(`${template.templateName}_back_${tempIdx}`);
    if (containerBack) {
      await htmlToImage.toJpeg(containerBack)
        .then((dataUrl) => {
          const imageName = `${template.templateId}_back.jpeg`;
          const imageBlob: Blob = this.service.dataURItoBlob(dataUrl);
          const imageFile = new File([imageBlob], imageName, { type: 'image/jpeg' });
          imageData.push(imgFile);              
        }).catch(function (error) {
          console.error('oops, something went wrong!', error);
        });
    }
  }


}

}

This works fine for max 10 to 15 record, but of templates size is more than 15 then application hangs(or crashes). For 10-15 records also it takes 15mins(which is very slow) Is there any better way to make it work?

about 4 years ago · Juan Pablo Isaza
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!