The module on npm exposes the pdfmake Printer, which the docs themselves do not cover. Using it is pretty simple though.
var fontDescriptors = {}; // required font setup, see ...
var docDefinition = {}; // this is what you see in all the docs
var Printer = require('pdfmake');
var printer = new Printer(fontDescriptors);
// get a reference to the PdfKit instance, which is a streaming interface
var pdfDoc = printer.createPdfKitDocument(docDefinition);
// pipe to a file or response object
function streamTo(pdfDoc) {
// writeStream can be an fs object, response object, etc
var writeStream = fs.createWriteStream('pdfs/output.pdf');
var pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(writeStream); // streaming interface
}
// turn the stream into a Buffer
function getDoc(pdfDoc, cb) {
// buffer the output
var chunks = [];
pdfDoc.on('data', function(chunk) {
chunks.push(chunk);
});
pdfDoc.on('end', function() {
var result = Buffer.concat(chunks);
cb(result, pdfDoc._pdfMakePages);
});
// close the stream
pdfDoc.end();
}| properties | description | default |
|---|---|---|
| header | ||
| footer | ||
| content | ||
| defaultStyle | { fontSize: 12, font: 'Roboto' } | |
| pageBreakBefore | ||
| styles | ||
| background | ||
| images | ||
| watermark |
tableLayouts - ???
autoPrint - ???
Nice, thanks! This helped me a lot