1
I am building a pdf of a sale. I am performing dummy data testing to validate the document layout. But the layout is "popping" as you go through the for.
This is my code:
createPdf() {
var column = [];
column.push({ text: 'Qtd.'});
column.push({ text: 'Produto/Serviço'});
column.push({ text: 'Valor unitário'});
column.push({ text: 'SubTotal'});
var value = [];
for(let i = 0; i < this.teste.length; i++){
value.push({text: this.teste[i].qtd, style: 'tableHeader'});
value.push({text: this.teste[i].nome, style: 'tableHeader'});
value.push({text: this.teste[i].preco, style: 'tableHeader'});
value.push({text: this.teste[i].total, style: 'tableHeader'});
}
/*value.push({ text: '01', style: 'tableHeader' });
value.push({ text: 'Calça masculina', style: 'tableHeader' });
value.push({ text: '150,00', style: 'tableHeader' });
value.push({ text: '150,00', alignment: 'right' });*/
var docDefinition = {
content: [
{ text: '01/01/2019', fontSize: 12, alignment: 'left' },
{ text: 'Venda', fontSize: 12, alignment: 'right', margin: [0, -12, 0, 0] },
{ text: '_______________________________________________________________________________________________' },
{ text: 'Nome do cliente', fontSize: 12, alignment: 'left', margin: [0, 12, 0, 0] },
{ text: '092.786.449-51', fontSize: 12, alignment: 'right', margin: [0, -14, 0, 0] },
{ text: '_______________________________________________________________________________________________' },
{
margin: [0, 15, 0, 0],
table: {
widths: ['10%', '*', '20%', '20%'],
headerRows: 1,
body: [
[column], [value]
]
}
},
{ text: 'Valor Total: 150,00', alignment: 'right', margin: [0, 10, 5, 0] },
{ text: '_______________________________________________________________________________________________' },
{ text: 'Condição de pagamento' },
{ text: 'Forma de pagamento: Cartão 2x', alignment: 'left', margin: [0, 15, 0, 0] },
{ text: '_______________________________________________________________________________________________' },
{ text: 'Observações: Testando o impresso', alignment: 'left', margin: [0, 10, 0, 0]},
],
footer: {
columns: [
{ text: 'Empresa Modelo - 092.786.449-51', alignment: 'center' },
]
},
};
this.pdfObj = pdfMake.createPdf(docDefinition);
}
The result I’m getting is this image, I need the columns and rows to be filled dynamically as the is traversed. My table header will be static, but the information will always be dynamic, as it will scroll through an array of sale items:
What I hope to get is:
Boy, unsuccessfully. I made the change but it’s still the same...
– Diego Estacho