I want to create a pdf file in my NodeJs server and then stream to the client, so it can download it, but I am not able to open the pdf file.
I created a pdf file using PDFKit, using the code in the documentation:
const doc = new PDFDocument({});
doc.text("Test");
const writeStream = fs.createWriteStream("MyTest.pdf");
writeStream.on("close", () => {
console.log("done");
});
doc.pipe(writeStream);
doc.end();
The pdf file gets created, but when I try to open it 2 things can happen:
- Adobe Acrobat does not open at all
- Adobe Acrobat opens after serveral minutes
I have the same behaviour if I open the file with Google Chrome.
I already looked into previous StackOverflow questions, like:
But these solutions seem not working for me.
Any ideas on how I have to proceed?