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:
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?
Found the issue, I was creating the file in Windows WSL and opening from WSL's fileSystem with Windows' Adobe Acrobat. This operation is very slow.
A quick workaround to see the result of the pdf operation is to copy the .pdf file to Windows' desktop and open it from there.