This is something I can’t understand and I would like to ask you all, giving this code:
async function processCodes() {
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream(`ordine_${ordine}.pdf`));
for (const code of codesToPrint) {
const qrCodeData = QRCode.toDataURL(code.code);
if (y + qrCodeHeight > pageHeight) {
doc.addPage();
y = 0; // Reset y position for the new page
}
// Add QR Code and text to the PDF
doc.image(qrCodeData, 50, y, { fit: [150, 150] });
doc.text(code.code, 220, y + 50, { width: 400 });
y += qrCodeHeight + spacing; // Increment y position
}
doc.end();
console.log('PDF generated!');
}
If i call this function like this:
processCodes().catch(err => console.error(err))
All good, everything works and i see the pdf.
If instead i use:
processCodes().catch(err => console.error(err)).finally(()=>process.exit(0))
The pdf i obtain is broken and can’t be open.
Any Ideas?
Im asking out of curiosity since make no sense to me