Last active
June 8, 2023 12:16
-
-
Save w33ble/38c5e0220d491148de1c to your computer and use it in GitHub Desktop.
Revisions
-
w33ble revised this gist
Jan 13, 2016 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,13 @@ The module on npm exposes the pdfmake Printer, which the docs themselves do not cover. Using it is pretty simple though. ```js var path = require('path'); var Printer = require('pdfmake'); // fonts are available in the test-env/tests/fonts path, this is a helper function fontPath(file) { retrun path.resolve('pdfmake', 'test-env', 'tests', 'fonts', file); } // required font setup, requires that you link to the fonts shipped with npm var fontDescriptors = { @@ -18,7 +23,6 @@ var fontDescriptors = { } }; var docDefinition = {}; // this is what you see in all the docs var printer = new Printer(fontDescriptors); // get a reference to the PdfKit instance, which is a streaming interface -
w33ble revised this gist
Jan 13, 2016 . 1 changed file with 12 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,18 @@ The module on npm exposes the pdfmake Printer, which the docs themselves do not cover. Using it is pretty simple though. ```js // fonts are available in the test-env/tests/fonts path, this is a helper var fontPath = (file) => require('path').resolve('pdfmake', 'test-env', 'tests', 'fonts', file); // required font setup, requires that you link to the fonts shipped with npm var fontDescriptors = { Roboto: { normal: fontPath('Roboto-Regular.ttf'), bold: fontPath('Roboto-Medium.ttf'), italics: fontPath('Roboto-Italic.ttf'), bolditalics: fontPath('Roboto-Italic.ttf'), } }; var docDefinition = {}; // this is what you see in all the docs var Printer = require('pdfmake'); var printer = new Printer(fontDescriptors); -
w33ble revised this gist
Jan 13, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ The module on npm exposes the pdfmake Printer, which the docs themselves do not cover. Using it is pretty simple though. ```js var fontDescriptors = {}; // required font setup, basically just link to the fonts shipped with npm var docDefinition = {}; // this is what you see in all the docs var Printer = require('pdfmake'); var printer = new Printer(fontDescriptors); -
w33ble revised this gist
Jan 12, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,7 @@ properties | default | description header | | [header](https://github.com/bpampuch/pdfmake#headers-and-footers), can be a function, placed on every page footer | | [footer](https://github.com/bpampuch/pdfmake#headers-and-footers), like header, but at the bottom content | | text, table, etc - the meat of the document defaultStyle | `{ fontSize: 12, font: 'Roboto' }` | applied to entire document styles | | available [style dictionaries](https://github.com/bpampuch/pdfmake#style-dictionaries) pageSize | | document page size, [string](https://github.com/bpampuch/pdfmake#page-dimensions-orientation-and-margins) or `{ width: number, height: number }` pageOrientation | portrait | document orientation, landscape or portrait -
w33ble revised this gist
Jan 12, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -70,8 +70,8 @@ Also specified as an object, this is where you can pass a few globally available Option Parameter | Description ---------------- | ----------- tableLayouts | Passed to `registerTableLayouts`, used to define globally available table layouts (see *Tables and Layouts* below) autoPrint | ??? ## Tables and Layouts -
w33ble revised this gist
Jan 12, 2016 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -41,9 +41,11 @@ function getDoc(pdfDoc, cb) { } ``` `createPdfKitDocument` takes 2 arguments, *docTemplate* and an optional *options*. ### docDefinition Specified as an object, the [document definition object](https://github.com/bpampuch/pdfmake#document-definition-object). properties | default | description ---------- | ------- | ----------- @@ -64,8 +66,12 @@ content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) ### options Also specified as an object, this is where you can pass a few globally available options to your document. Available options include: Option Parameter | Description ---------------- | ----------- `tableLayouts` | Passed to `registerTableLayouts`, used to define globally available table layouts (see *Tables and Layouts* below) `autoPrint` | ??? ## Tables and Layouts -
w33ble revised this gist
Jan 12, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -64,10 +64,10 @@ content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) ### options - `tableLayouts` - Used to define globally available table layouts, see *Tables and Layouts* below - `autoPrint` - ??? ## Tables and Layouts Tables have a few pre-defined layouts available ([code](https://github.com/bpampuch/pdfmake/blob/02a859b90b262921bb1a00409c7f548332dce33b/src/printer.js#L143-L175)). They can be used by specifying a `layout: 'LayoutName'` in the table definition. The included styles are *noBorders*, *headerLineOnly*, and *lightHorizontalLines*, and you can see examples of all three near the bottom of the *Tables* example in the [playground](http://pdfmake.org/playground.html). -
w33ble revised this gist
Jan 12, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -69,13 +69,13 @@ content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) ## Tables and layouts Tables have a few pre-defined layouts available ([code](https://github.com/bpampuch/pdfmake/blob/02a859b90b262921bb1a00409c7f548332dce33b/src/printer.js#L143-L175)). They can be used by specifying a `layout: 'LayoutName'` in the table definition. The included styles are *noBorders*, *headerLineOnly*, and *lightHorizontalLines*, and you can see examples of all three near the bottom of the *Tables* example in the [playground](http://pdfmake.org/playground.html). If no layout is specified, the default is used. This provides a 1px black line around each cell, with a top/bottom padding of 2px and a left/right padding of 4px ([code](https://github.com/bpampuch/pdfmake/blob/02a859b90b262921bb1a00409c7f548332dce33b/src/printer.js#L179-L188)) ### Custom Layouts You can build your own custom layout as well, specifying your own line width, color and cell padding. Each value takes a callback function, which is passed the *row index* and *table node reference* ([code](https://github.com/bpampuch/pdfmake/blob/02a859b90b262921bb1a00409c7f548332dce33b/src/tableProcessor.js#L77)) Here's an example of how to do that, using the default layout as the values: -
w33ble revised this gist
Jan 12, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -66,7 +66,7 @@ content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) - `tableLayouts` - ??? - `autoPrint` - ??? ## Tables and layouts Tables have a few pre-defined layouts available. They can be used by specifying a `layout: 'LayoutName'` in the table definition. The included styles are *noBorders*, *headerLineOnly*, and *lightHorizontalLines*, and you can see examples of all three near the bottom of the *Tables* example in the [playground](http://pdfmake.org/playground.html). -
w33ble revised this gist
Jan 12, 2016 . 1 changed file with 28 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,7 @@ function getDoc(pdfDoc, cb) { } ``` ### docDefinition The [document definition object](https://github.com/bpampuch/pdfmake#document-definition-object) that you pass to `pdfmake` @@ -62,7 +62,32 @@ watermark | | info | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) ### options - `tableLayouts` - ??? - `autoPrint` - ??? - ## Tables and layouts Tables have a few pre-defined layouts available. They can be used by specifying a `layout: 'LayoutName'` in the table definition. The included styles are *noBorders*, *headerLineOnly*, and *lightHorizontalLines*, and you can see examples of all three near the bottom of the *Tables* example in the [playground](http://pdfmake.org/playground.html). If no layout is specified, the default is used. This provides a 1px black line around each cell, with a top/bottom padding of 2px and a left/right padding of 4px. ### Custom Layouts You can build your own custom layout as well, specifying your own line width, color and cell padding. Each value takes a callback function, which is passed the *row index* and *table node reference*. Here's an example of how to do that, using the default layout as the values: ```js layout: { hLineWidth: function(i, node) { return 1; }, //return node.table.headerRows && i === node.table.headerRows && 3 || 0; }, vLineWidth: function(i, node) { return 1; }, hLineColor: function(i, node) { return 'black'; }, vLineColor: function(i, node) { return 'black'; }, paddingLeft: function(i, node) { return 4; }, //i && 4 || 0; }, paddingRight: function(i, node) { return 4; }, //(i < node.table.widths.length - 1) ? 4 : 0; }, paddingTop: function(i, node) { return 2; }, paddingBottom: function(i, node) { return 2; } }; ``` -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -47,8 +47,8 @@ The [document definition object](https://github.com/bpampuch/pdfmake#document-de properties | default | description ---------- | ------- | ----------- header | | [header](https://github.com/bpampuch/pdfmake#headers-and-footers), can be a function, placed on every page footer | | [footer](https://github.com/bpampuch/pdfmake#headers-and-footers), like header, but at the bottom content | | text, table, etc - the meat of the document defaultStyle | { fontSize: 12, font: 'Roboto' } | applied to entire document styles | | available [style dictionaries](https://github.com/bpampuch/pdfmake#style-dictionaries) -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -64,5 +64,5 @@ content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) ## options - `tableLayouts` - ??? - `autoPrint` - ??? -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -51,9 +51,9 @@ header | | [header](https://github.com/bpampuch/pdfmake#headers-and-footers), pl footer | | [footer](https://github.com/bpampuch/pdfmake#headers-and-footers), placed on every page content | | text, table, etc - the meat of the document defaultStyle | { fontSize: 12, font: 'Roboto' } | applied to entire document styles | | available [style dictionaries](https://github.com/bpampuch/pdfmake#style-dictionaries) pageSize | | document page size, [string](https://github.com/bpampuch/pdfmake#page-dimensions-orientation-and-margins) or `{ width: number, height: number }` pageOrientation | portrait | document orientation, landscape or portrait pageMargins | | document margins - [left, top, right, bottom] or [horizontal, vertical] pageBreakBefore | | function, executed to determine if there should be a page break before content background | | [background-layer](https://github.com/bpampuch/pdfmake#background-layer) added on every page, can be a function -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 17 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -43,17 +43,24 @@ function getDoc(pdfDoc, cb) { ## docDefinition The [document definition object](https://github.com/bpampuch/pdfmake#document-definition-object) that you pass to `pdfmake` properties | default | description ---------- | ------- | ----------- header | | [header](https://github.com/bpampuch/pdfmake#headers-and-footers), placed on every page footer | | [footer](https://github.com/bpampuch/pdfmake#headers-and-footers), placed on every page content | | text, table, etc - the meat of the document defaultStyle | { fontSize: 12, font: 'Roboto' } | applied to entire document width: number, height: number }` styles | | available [style dictionaries](https://github.com/bpampuch/pdfmake#style-dictionaries) pageSize | | document page size, [string](https://github.com/bpampuch/pdfmake#page-dimensions-orientation-and-margins) or `{ pageOrientation | portrait | document orientation, landscape or portrait pageMargins | | document margins - [left, top, right, bottom] or [horizontal, vertical] pageBreakBefore | | function, executed to determine if there should be a page break before content background | | [background-layer](https://github.com/bpampuch/pdfmake#background-layer) added on every page, can be a function images | | similar to styles, globally-available image content - most useful as `'data:image/jpeg;base64,...'` watermark | | info | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata) ## options -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,7 @@ function streamTo(pdfDoc) { } // turn the stream into a Buffer // Usage: getDoc(pdfDoc, function (err, buffer, pages) { var base64 = buffer.toString('base64'); /* app logic */ }); function getDoc(pdfDoc, cb) { // buffer the output var chunks = []; @@ -31,8 +32,9 @@ function getDoc(pdfDoc, cb) { }); pdfDoc.on('end', function() { var result = Buffer.concat(chunks); cb(null, result, pdfDoc._pdfMakePages); }); pdfDoc.on('error', cb); // close the stream pdfDoc.end(); -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 50 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,48 @@ # pdfmake ## Use in node.js The module on npm exposes the pdfmake Printer, which the docs themselves do not cover. Using it is pretty simple though. ```js 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(); } ``` ## docDefinition properties | description | default ---------- | ----------- | ------- header | | footer | | content | | @@ -9,3 +52,8 @@ styles | | background | | images | | watermark | | ## options `tableLayouts` - ??? `autoPrint` - ??? -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ option | description | default ------ | ----------- | ------- header | | footer | | content | | defaultStyle | | { fontSize: 12, font: 'Roboto' } pageBreakBefore | | styles | | background | | images | | watermark | | -
w33ble revised this gist
Jan 8, 2016 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,6 @@ option | description | default ------ | ----------- | ------- defaultStyle | | { fontSize: 12, font: 'Roboto' } content | | styles | | background | | -
w33ble created this gist
Jan 8, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ option | description | default ------ | ----------- | ------- defaultStyle | | { fontSize: 12 font: 'Roboto' } content | | styles | | background | | header | | footer | | images | | watermark | | pageBreakBefore | |