From 7e4b9b895b2656964dcacea9cfcafb69ad875ae0 Mon Sep 17 00:00:00 2001 From: Libor M Date: Fri, 31 Dec 2021 16:45:45 +0100 Subject: [PATCH] update table layouts --- content/document-definition-object/tables.md | 32 +++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/content/document-definition-object/tables.md b/content/document-definition-object/tables.md index 9d07f36..ef06a7b 100644 --- a/content/document-definition-object/tables.md +++ b/content/document-definition-object/tables.md @@ -50,7 +50,8 @@ Available table layouts: Own table layouts must be defined before calling `pdfMake.createPdf(docDefinition)`. ```js -pdfMake.tableLayouts = { +// define table layouts +var tableLayouts = { exampleLayout: { hLineWidth: function (i, node) { if (i === 0 || i === node.table.body.length) { @@ -73,28 +74,19 @@ pdfMake.tableLayouts = { } }; +// add table layouts +pdfMake.addTableLayouts(tableLayouts); + // download the PDF pdfMake.createPdf(docDefinition).download(); ``` -Alternatively, you can pass the tableLayouts directly to `createPdf` without changing the global value: - -- On the client side: - -```js -pdfMake.createPdf(docDefinition, tableLayouts).download(); - -// The full signature of createPdf looks like this. -// tableLayouts, fonts and vfs are all optional - falsy values will cause -// pdfMake.tableLayouts, pdfMake.fonts or pdfMake.vfs to be used. -pdfMake.createPdf(docDefinition, tableLayouts, fonts, vfs) -``` - On the server side: ```js -var PdfPrinter = require('pdfmake'); -var printer = new PdfPrinter(fonts); +var pdfmake = require('pdfmake'); +pdfmake.addFonts(fonts); // Declaring your layout var myTableLayouts = { @@ -106,11 +98,15 @@ var myTableLayouts = { }; // Building the PDF -var pdfDoc = printer.createPdfKitDocument(docDefinition, {tableLayouts: myTableLayouts}); +var pdf = pdfmake.createPdf(docDefinition); // Writing it to disk -pdfDoc.pipe(fs.createWriteStream('document.pdf')); -pdfDoc.end(); +pdf.write('document.pdf').then(() => { + // success event +}, err => { + // error event + console.error(err); +}); ``` All concepts related to tables are covered by TABLES example in [playground](http://pdfmake.org/playground.html).