Create a PDF document in Node.js
masterTo create a PDF, require the pdfkit module and instantiate the PDFDocument class. PDFDocument instances are readable Node streams. You must use the pipe method to direct the output to a writable stream (like a file or an HTTP response) and call end() to finalize the document.
Note: The write and output methods are deprecated and should not be used.
const PDFDocument = require('pdfkit');
const fs = require('fs');
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('/path/to/file.pdf'));
// add stuff to PDF here...
doc.end();