Hello everyone, I am in my last stage of this project. I am trying to preview the data in angular goes wrong. Does not get send the correct data.
I had succes generating a pdf and saving it but not any succes with trying to preview. First of all i need to press like twice on the button loadpdf before the iframe shows up and then it does not load the data i generate
i feel like i am doing this correct.
async previewPDF(data: any, res: Response): Promise<void> {
const doc = new PDFKit();
const endX = doc.page.width - 20;
const codelogoPath = path.join(
__dirname,
'..',
'..',
'..',
'apps',
'codex-api',
'src',
'assets',
'logos',
'mylogo.png'
);
doc.image(codelogoPath, 425, 10, {
fit: [170, 170],
align: 'center',
});
doc.font('Helvetica');
doc.text(data.addressclient, 430, 111);
doc.text(data.postalclient + ' ' + data.city, 430, 125);
doc.text(data.land, 430, 139);
doc.font('Helvetica-Bold');
doc.text('Codex:', 20, 690);
doc.text('Ondernemingsnummer: BE 0000.111.222', 20, 700);
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'inline; filename=preview.pdf');
doc.pipe(res);
doc.end();
}
}
@Post('/preview')
async previewPDF(@Body() data: any, @Res() res: Response) {
const fileBuffer = await this.pdfService.previewPDF(data, res);
res.setHeader('Content-Type', 'application/pdf');
res.send(fileBuffer);
}```