Last active
February 12, 2022 14:14
-
-
Save NikhilNanjappa/d218b21b92c714c7905a18057c1d9fdb to your computer and use it in GitHub Desktop.
generatePdfStoreServer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pdfMakePrinter = require('pdfmake/src/printer'); | |
const fs = require('fs'); | |
function generatePdf(docDefinition, successCallback, errorCallback) => { | |
try { | |
const fontDescriptors = { ... }; | |
const printer = new pdfMakePrinter(fontDescriptors); | |
const doc = printer.createPdfKitDocument(docDefinition); | |
doc.pipe( | |
fs.createWriteStream('docs/filename.pdf').on("error", (err) => { | |
errorCallback(err.message); | |
}) | |
); | |
doc.on('end', () => { | |
successCallback("PDF successfully created and stored"); | |
}); | |
doc.end(); | |
} catch(err) { | |
throw(err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment