Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda