const doc = new PDFDocument();
// do stuff here
const writeStream = fs.createWriteStream('output.pdf')
doc.pipe(writeStream);
doc.end();
above code generating pdf file but cannot open pdf, it is showing an error that file has damaged.
const doc = new PDFDocument();
// do stuff here
const writeStream = fs.createWriteStream('output.pdf')
doc.pipe(writeStream);
doc.end();
above code generating pdf file but cannot open pdf, it is showing an error that file has damaged.
You probably have an async issue where you're trying to access/return the doc before it's done writing to disk.
Fix with a handler :
writeStream.on('finish', () => { .. your code here .. });