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

1K
Visualizações
Merging multiple pdf Using pdfMake.js in Angular

I was able to create a single pdf file using for the following code.

this.docDefinition = {
      
      pageSize: 'LETTER',
      pageOrientation: 'landscape',
      pageMargins: [40, 30, 40, 30],

      header: function (page, pages) {
        return {
          height: 14,
          text: 'Sample',
          style: 'titleHeader',
          alignment: 'center'
        };
      },
      
      content: [
        this.buildSectionPatientInfo(),
        {
          table: {
            widths: ['50%', '50%'],
            headerRows: 0,
            body: [
              [
                // RIGHT SIDE
                [
                 
                  this.buildSectionServices(),    
                  this.buildSectionLabUseOnly()
                ],
                // LEFT SIDE
                [
                  
                  this.buildSectionFrame(),
                  this.buildSectionSpecialInstructionsLab()
                ]
              ]
            ]
          },
          layout: 'noBorders'
        },
      ],
      styles: {
        titleHeader: {
          fontSize: 16,
          bold: true,
          margin: [0, 10, 0, 0],
        },
        tableHeader: {
          bold: true,
          fontSize: 13,
          color: 'black'
        }
      },

      defaultStyle: {
        fontSize: 9,
        lineHeight: .9
      }
    };

    try {
      pdfMake.createPdf(this.docDefinition).open();
    } catch (e) {
      // check popup/ad blockers
      alert(e.toString());
    }

But now I having trouble of creating multiple pdf files and merge it into one pfd. I tried to put a for loop inside content but it errors out.

.......................

content: [
for (const labOrder of selectedLabOrders) {
        this.buildSectionPatientInfo(),
        {
          table: {
            widths: ['50%', '50%'],
            headerRows: 0,
            body: [
              [
                // RIGHT SIDE
                [
                  
                  this.buildSectionLabInfo(),
                  this.buildSectionLabUseOnly()
                ],
                // LEFT SIDE
                [
                  
                  this.buildSectionFrame(),
                  this.buildSectionSpecialInstructionsLab()
                ]
              ]
            ]
          },
          layout: 'noBorders'
        },
}
      ],

.............

I would greatly appreciate if anybody can provide a solution for this.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Perform your loops before creating the docDefinition. Then just append it to your content like so:

const tables = [];

for (const labOrder of selectedLabOrders) {
   tables.push(
     this.buildSectionPatientInfo(),
        {
          table: {
            widths: ['50%', '50%'],
            headerRows: 0,
            body: [
              [
                // RIGHT SIDE
                [
                  
                  this.buildSectionLabInfo(),
                  this.buildSectionLabUseOnly()
                ],
                // LEFT SIDE
                [
                  
                  this.buildSectionFrame(),
                  this.buildSectionSpecialInstructionsLab()
                ]
              ]
            ]
          },
          layout: 'noBorders'
        })
}

Then add tables to your content:

this.docDefinition = {
      
      pageSize: 'LETTER',
      pageOrientation: 'landscape',
      pageMargins: [40, 30, 40, 30],

      header: function (page, pages) {
        return {
          height: 14,
          text: 'Sample',
          style: 'titleHeader',
          alignment: 'center'
        };
      },
      
      content: [
        { tables }
      ],
      styles: {
        titleHeader: {
          fontSize: 16,
          bold: true,
          margin: [0, 10, 0, 0],
        },
        tableHeader: {
          bold: true,
          fontSize: 13,
          color: 'black'
        }
      },

      defaultStyle: {
        fontSize: 9,
        lineHeight: .9
      }
    };

    try {
      pdfMake.createPdf(this.docDefinition).open();
    } catch (e) {
      // check popup/ad blockers
      alert(e.toString());
    }

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