Skip to content

Instantly share code, notes, and snippets.

@w33ble
Last active June 8, 2023 12:16
Show Gist options
  • Select an option

  • Save w33ble/38c5e0220d491148de1c to your computer and use it in GitHub Desktop.

Select an option

Save w33ble/38c5e0220d491148de1c to your computer and use it in GitHub Desktop.

Revisions

  1. w33ble revised this gist Jan 13, 2016. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions pdfmake docs.md
    Original 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
    var fontPath = (file) => require('path').resolve('pdfmake', 'test-env', 'tests', 'fonts', file);
    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 = require('pdfmake');
    var printer = new Printer(fontDescriptors);

    // get a reference to the PdfKit instance, which is a streaming interface
  2. w33ble revised this gist Jan 13, 2016. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion pdfmake docs.md
    Original 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
    var fontDescriptors = {}; // required font setup, basically just link to the fonts shipped with npm
    // 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);
  3. w33ble revised this gist Jan 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pdfmake docs.md
    Original 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, see ...
    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);
  4. w33ble revised this gist Jan 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pdfmake docs.md
    Original 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
    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
  5. w33ble revised this gist Jan 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pdfmake docs.md
    Original 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` | ???
    tableLayouts | Passed to `registerTableLayouts`, used to define globally available table layouts (see *Tables and Layouts* below)
    autoPrint | ???

    ## Tables and Layouts

  6. w33ble revised this gist Jan 12, 2016. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions pdfmake docs.md
    Original 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

    The [document definition object](https://github.com/bpampuch/pdfmake#document-definition-object) that you pass to `pdfmake`
    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

    - `tableLayouts` - Used to define globally available table layouts, see *Tables and Layouts* below
    - `autoPrint` - ???
    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

  7. w33ble revised this gist Jan 12, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pdfmake docs.md
    Original file line number Diff line number Diff line change
    @@ -64,10 +64,10 @@ content | | [metadata](https://github.com/bpampuch/pdfmake#document-metadata)

    ### options

    - `tableLayouts` - ???
    - `tableLayouts` - Used to define globally available table layouts, see *Tables and Layouts* below
    - `autoPrint` - ???

    ## Tables and layouts
    ## 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).

  8. w33ble revised this gist Jan 12, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions pdfmake docs.md
    Original 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. 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).
    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.
    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*.
    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:

  9. w33ble revised this gist Jan 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pdfmake docs.md
    Original 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).
  10. w33ble revised this gist Jan 12, 2016. 1 changed file with 28 additions and 3 deletions.
    31 changes: 28 additions & 3 deletions pdfmake docs.md
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ function getDoc(pdfDoc, cb) {
    }
    ```

    ## docDefinition
    ### 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
    ### options

    - `tableLayouts` - ???
    - `autoPrint` - ???
    - `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; }
    };
    ```
  11. w33ble revised this gist Jan 8, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pdfmake docs.md
    Original 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), placed on every page
    footer | | [footer](https://github.com/bpampuch/pdfmake#headers-and-footers), placed on every page
    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)
  12. w33ble revised this gist Jan 8, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pdfmake docs.md
    Original 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` - ???
    - `tableLayouts` - ???
    - `autoPrint` - ???
  13. w33ble revised this gist Jan 8, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pdfmake docs.md
    Original 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
    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
    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
  14. w33ble revised this gist Jan 8, 2016. 1 changed file with 17 additions and 10 deletions.
    27 changes: 17 additions & 10 deletions pdfmake docs.md
    Original file line number Diff line number Diff line change
    @@ -43,17 +43,24 @@ function getDoc(pdfDoc, cb) {

    ## docDefinition

    properties | description | default
    ---------- | ----------- | -------
    header | |
    footer | |
    content | |
    defaultStyle | | { fontSize: 12, font: 'Roboto' }
    pageBreakBefore | |
    styles | |
    background | |
    images | |
    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

  15. w33ble revised this gist Jan 8, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion pdfmake docs.md
    Original 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(result, pdfDoc._pdfMakePages);
    cb(null, result, pdfDoc._pdfMakePages);
    });
    pdfDoc.on('error', cb);

    // close the stream
    pdfDoc.end();
  16. w33ble revised this gist Jan 8, 2016. 1 changed file with 50 additions and 2 deletions.
    52 changes: 50 additions & 2 deletions pdfmake docs.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,48 @@
    option | description | default
    ------ | ----------- | -------
    # 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` - ???
  17. w33ble revised this gist Jan 8, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions pdfmake docs.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    option | description | default
    ------ | ----------- | -------
    defaultStyle | | { fontSize: 12, font: 'Roboto' }
    header | |
    footer | |
    content | |
    defaultStyle | | { fontSize: 12, font: 'Roboto' }
    pageBreakBefore | |
    styles | |
    background | |
    header | |
    footer | |
    images | |
    watermark | |
    pageBreakBefore | |
  18. w33ble revised this gist Jan 8, 2016. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions pdfmake docs.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,6 @@
    option | description | default
    ------ | ----------- | -------
    defaultStyle | | {
    fontSize: 12
    font: 'Roboto'
    }
    defaultStyle | | { fontSize: 12, font: 'Roboto' }
    content | |
    styles | |
    background | |
  19. w33ble created this gist Jan 8, 2016.
    14 changes: 14 additions & 0 deletions pdfmake docs.md
    Original 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 | |