Pude crear un solo archivo pdf usando el siguiente código.
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()); }
Pero ahora tengo problemas para crear varios archivos pdf y fusionarlos en un pdf. Intenté poner un bucle for dentro del contenido, pero se produce un error.
.......................
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' }, } ],
.............
Agradecería mucho si alguien puede proporcionar una solución para esto.
Realice sus bucles antes de crear la docDefinition. Luego simplemente agréguelo a su contenido así:
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' }) }
Luego agregue tablas a su contenido:
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()); }