I need to create a pdf file using pdfkit in node.js:
I have this code:
doc = new PDFDocument;
doc.pipe; fs.createWriteStream('output.pdf');
doc.fontSize(15);
doc.text('Generate PDF!');
doc.end();
And it will create a pdf file: 'output.pdf', but every time I open the file, the file is corrupted. It says: "The document cannot be opened. A text document of type text (text / plain) is not supported . "
And then I tried:
doc = new PDFDocument;
doc.pipe fs.createWriteStream('output.pdf');
doc.fontSize(15);
doc.text('Generate PDF!');
doc.end();
But there is an error:
doc.pipe fs.createWriteStream('output.pdf');
^^
Syntax error: Unexpected Identifier
Then, what is the correct way to create PDF files in nodejs? Especially regarding:
doc.pipe fs.createWriteStream
Please help me. Thanks in advance!
source
share