diff --git a/docs/bundle/index.md b/docs/bundle/index.md index 47d5c26..7ecf27e 100644 --- a/docs/bundle/index.md +++ b/docs/bundle/index.md @@ -28,6 +28,9 @@ - [PDFTable](#interface-pdfpdftable) - [PDFRow](#interface-pdfpdfrow) - [PDFColumn](#interface-pdfpdfcolumn) + - [PDFBorderColor](#type-alias-pdfpdfbordercolor) + - [PDFBorderWidth](#type-alias-pdfpdfborderwidth) + - [PDFPadding](#type-alias-pdfpdfpadding) - [Table](#class-pdftable) - Constructor @@ -327,38 +330,11 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0) - **pdf.align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the table `optional` - **pdf.backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the table. `optional` -- **pdf.borderColor** `union` The colors of the border `optional` - - - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - `tuple` - - - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - -- **pdf.borderWidth** `union` Width of the borders of the row. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **pdf.borderColor** [`PDFBorderColor`](#type-alias-pdfpdfbordercolor) The colors of the border `optional` +- **pdf.borderWidth** [`PDFBorderWidth`](#type-alias-pdfpdfborderwidth) Width of the borders of the row. `optional` - **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the table. `optional` - **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the table. `optional` -- **pdf.padding** `union` Cell padding of the table cells. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **pdf.padding** [`PDFPadding`](#type-alias-pdfpdfpadding) Cell padding of the table cells. `optional` - **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside table. `optional` - **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional` - **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the table `optional` @@ -368,7 +344,7 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0) #### Interface: pdf.PDFRow -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L30C0) - **pdf.columns** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table columns. @@ -376,42 +352,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0) - **pdf.align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the row `optional` - **pdf.backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the row. `optional` -- **pdf.borderColor** `union` The colors of the border `optional` - - - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - `tuple` - - - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - -- **pdf.borderWidth** `union` Width of the borders of the row. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **pdf.borderColor** [`PDFBorderColor`](#type-alias-pdfpdfbordercolor) The colors of the border `optional` +- **pdf.borderWidth** [`PDFBorderWidth`](#type-alias-pdfpdfborderwidth) Width of the borders of the row. `optional` - **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the row. `optional` - **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the row. `optional` - **pdf.header** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) A header row gets inserted automatically on new pages. Only one header row is allowed. `optional` - **pdf.height** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Height of the row. Overrides minHeight and maxHeight `optional` - **pdf.maxHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Maximum height of the row `optional` - **pdf.minHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Minimum height of the row `optional` -- **pdf.padding** `union` Cell padding of the table cells inside the row. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **pdf.padding** [`PDFPadding`](#type-alias-pdfpdfpadding) Cell padding of the table cells inside the row. `optional` - **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the row. `optional` - **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional` - **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the row `optional` @@ -420,53 +369,107 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0) #### Interface: pdf.PDFColumn -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L62C0) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L63C0) - **pdf.text** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) | [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Cell text. - **pdf.align** `"center"` | `"left"` | `"right"` Horizontal alignment of the text inside the cell `optional` - **pdf.backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the cell. `optional` -- **pdf.borderColor** `union` The colors of the border `optional` +- **pdf.borderColor** [`PDFBorderColor`](#type-alias-pdfpdfbordercolor) The colors of the border `optional` +- **pdf.borderWidth** [`PDFBorderWidth`](#type-alias-pdfpdfborderwidth) Width of the borders of the row. `optional` +- **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the cell. `optional` +- **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the cell. `optional` +- **pdf.padding** [`PDFPadding`](#type-alias-pdfpdfpadding) Cell padding of the table cell. `optional` +- **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the cell. `optional` +- **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional` +- **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of the text inside the cell `optional` +- **pdf.width** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Width of the cell. `optional` - - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - `tuple` +
- - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) +#### Type alias: pdf.PDFBorderColor -- **pdf.borderWidth** `union` Width of the borders of the row. `optional` +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L91C0) - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` +##### Type - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +`union` -- **pdf.fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the cell. `optional` -- **pdf.fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the cell. `optional` -- **pdf.padding** `union` Cell padding of the table cell. `optional` +- [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) +- `tuple` - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` + - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +- `tuple` -- **pdf.textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the cell. `optional` -- **pdf.textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional` -- **pdf.verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of the text inside the cell `optional` -- **pdf.width** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Width of the cell. `optional` + - vertical [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - horizontal [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + +##### Description + +Can be used to set the color of the border of a table, row or column. + +
+ +#### Type alias: pdf.PDFBorderWidth + +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L97C0) + +##### Type + +`union` + +- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +- `tuple` + + - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +- `tuple` + + - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +##### Description + +Can be used to set the width of the border of a table, row or column. + +
+ +#### Type alias: pdf.PDFPadding + +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L103C0) + +##### Type + +`union` + +- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +- `tuple` + + - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +- `tuple` + + - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +##### Description + +Can be used to set the padding of a table cell.
#### Class: pdf.Table -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L138C0) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L157C0) ##### Description @@ -516,7 +519,7 @@ pdf.end(); ##### Constructor: new pdf.Table(data) -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L145C2) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L164C2) ###### Parameter @@ -536,7 +539,7 @@ Creates a new Table instance. `public` -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L169C2) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L188C2) ###### Parameters diff --git a/docs/pdf/index.md b/docs/pdf/index.md index 4281078..cc8ec6e 100644 --- a/docs/pdf/index.md +++ b/docs/pdf/index.md @@ -28,6 +28,9 @@ - Method - [attachTo(doc\[, x\]\[, y\])](#method-tableattachtodoc-x-y) + - [PDFBorderColor](#type-alias-pdfbordercolor) + - [PDFBorderWidth](#type-alias-pdfborderwidth) + - [PDFPadding](#type-alias-pdfpadding) - [PDFTable](#interface-pdftable) - [PDFRow](#interface-pdfrow) - [PDFColumn](#interface-pdfcolumn) @@ -236,7 +239,7 @@ Attaches the Swiss QR Code to a PDF document. ### Class: Table -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L138C0) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L157C0) #### Description @@ -286,7 +289,7 @@ pdf.end(); #### Constructor: new Table(data) -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L145C2) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L164C2) ##### Parameter @@ -306,7 +309,7 @@ Creates a new Table instance. `public` -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L169C2) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L188C2) ##### Parameters @@ -329,48 +332,102 @@ every row that no longer fits on a page.
-### Interface: PDFTable +### Type alias: PDFBorderColor -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L91C0) -- **rows** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table rows. +#### Type - - [`PDFRow`](#interface-pdfrow) +`union` -- **align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the table `optional` -- **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the table. `optional` -- **borderColor** `union` The colors of the border `optional` +- [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) +- `tuple` - - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - `tuple` + - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) +- `tuple` -- **borderWidth** `union` Width of the borders of the row. `optional` + - vertical [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) + - horizontal [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` +#### Description - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +Can be used to set the color of the border of a table, row or column. -- **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the table. `optional` -- **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the table. `optional` -- **padding** `union` Cell padding of the table cells. `optional` +
+ +### Type alias: PDFBorderWidth + +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L97C0) + +#### Type + +`union` + +- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +- `tuple` + + - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +- `tuple` + + - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +#### Description + +Can be used to set the width of the border of a table, row or column. + +
+ +### Type alias: PDFPadding + +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L103C0) + +#### Type + +`union` + +- [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +- `tuple` + + - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +- `tuple` + + - vertical [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - horizontal [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + +#### Description + +Can be used to set the padding of a table cell. + +
+ +### Interface: PDFTable + +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0) - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` +- **rows** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table rows. - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) + - [`PDFRow`](#interface-pdfrow) +- **align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the table `optional` +- **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the table. `optional` +- **borderColor** [`PDFBorderColor`](#type-alias-pdfbordercolor) The colors of the border `optional` +- **borderWidth** [`PDFBorderWidth`](#type-alias-pdfborderwidth) Width of the borders of the row. `optional` +- **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the table. `optional` +- **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the table. `optional` +- **padding** [`PDFPadding`](#type-alias-pdfpadding) Cell padding of the table cells. `optional` - **textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside table. `optional` - **textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional` - **verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the table `optional` @@ -380,7 +437,7 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0) ### Interface: PDFRow -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L30C0) - **columns** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table columns. @@ -388,42 +445,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0) - **align** `"center"` | `"left"` | `"right"` Horizontal alignment of texts inside the row `optional` - **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the row. `optional` -- **borderColor** `union` The colors of the border `optional` - - - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - `tuple` - - - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - -- **borderWidth** `union` Width of the borders of the row. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **borderColor** [`PDFBorderColor`](#type-alias-pdfbordercolor) The colors of the border `optional` +- **borderWidth** [`PDFBorderWidth`](#type-alias-pdfborderwidth) Width of the borders of the row. `optional` - **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the row. `optional` - **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the row. `optional` - **header** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) A header row gets inserted automatically on new pages. Only one header row is allowed. `optional` - **height** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Height of the row. Overrides minHeight and maxHeight `optional` - **maxHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Maximum height of the row `optional` - **minHeight** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Minimum height of the row `optional` -- **padding** `union` Cell padding of the table cells inside the row. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **padding** [`PDFPadding`](#type-alias-pdfpadding) Cell padding of the table cells inside the row. `optional` - **textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the row. `optional` - **textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional` - **verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of texts inside the row `optional` @@ -432,43 +462,16 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L29C0) ### Interface: PDFColumn -Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L62C0) +Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L63C0) - **text** [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) | [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Cell text. - **align** `"center"` | `"left"` | `"right"` Horizontal alignment of the text inside the cell `optional` - **backgroundColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Background color of the cell. `optional` -- **borderColor** `union` The colors of the border `optional` - - - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - `tuple` - - - top [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - right [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - bottom [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - - left [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - -- **borderWidth** `union` Width of the borders of the row. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **borderColor** [`PDFBorderColor`](#type-alias-pdfbordercolor) The colors of the border `optional` +- **borderWidth** [`PDFBorderWidth`](#type-alias-pdfborderwidth) Width of the borders of the row. `optional` - **fontName** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Font of the text inside the cell. `optional` - **fontSize** [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) Font size of the text inside the cell. `optional` -- **padding** `union` Cell padding of the table cell. `optional` - - - [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - `tuple` - - - top [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - right [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - bottom [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - - left [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) - +- **padding** [`PDFPadding`](#type-alias-pdfpadding) Cell padding of the table cell. `optional` - **textColor** [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) Text color of texts inside the cell. `optional` - **textOptions** `TextOptions` Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). `optional` - **verticalAlign** `"bottom"` | `"center"` | `"top"` Vertical alignment of the text inside the cell `optional` diff --git a/src/pdf/table.test.snap b/src/pdf/table.test.snap index 18010ac..1de534f 100644 --- a/src/pdf/table.test.snap +++ b/src/pdf/table.test.snap @@ -825,126 +825,236 @@ BT [<323030> 0] TJ ET Q +", +] +`; + +exports[`table > should convert the values of tuples shorthand syntax correctly 1`] = ` +[ + "1 0 0 -1 0 595.28 cm 72 72 m -172 72 m -372 72 m -572 72 m +769.89 72 m 72 72 m -272 122 m -372 122 m -572 122 m +769.89 72 m 72 72 m -272 172 m -472 172 m -572 172 m +769.89 72 m 72 72 m -238.666667 222 m -405.333333 222 m -572 222 m +769.89 72 m 72 72 m -172 272 m -272 272 m -372 272 m +769.89 72 m 72 72 m -272 322 m -472 322 m -672 322 m +769.89 72 m 72 72 m -172 72 m -372 72 m -572 72 m +769.89 72 m 72 72 m -272 122 m -372 122 m -572 122 m +769.89 72 m 72 72 m -272 172 m -472 172 m -572 172 m +769.89 124.716 m 72 72 m -238.666667 222 m -405.333333 222 m -572 222 m +769.89 164.716 m 72 72 m -172 272 m -272 272 m -372 272 m +769.89 217.432 m 72 72 m -272 322 m -472 322 m -672 322 m +769.89 257.432 m 72 72 m -172 72 m -372 72 m -572 72 m +769.89 310.148 m 72 72 m -272 122 m -372 122 m -572 122 m +769.89 350.148 m 72 72 m -272 172 m -472 172 m -572 172 m +769.89 72 m 72 72 m -238.666667 222 m -405.333333 222 m -572 222 m +769.89 124.716 m 72 72 m -172 272 m -272 272 m -372 272 m +769.89 164.716 m 72 72 m -272 322 m -472 322 m -672 322 m +769.89 217.432 m 72 72 m -172 72 m -372 72 m -572 72 m +769.89 257.432 m 72 72 m -272 122 m -372 122 m -572 122 m +769.89 310.148 m 72 72 m -272 172 m -472 172 m -572 172 m +769.89 350.148 m 72 72 m -238.666667 222 m -405.333333 222 m -572 222 m +769.89 72 m +[] 0 d +0 j +0 J +/Gs1 gs +72 126.716 m +72 70 l +/DeviceRGB CS +1 0 0 SCN +4 w +S +769.89 70 m +769.89 126.716 l +/DeviceRGB CS +1 0 0 SCN +4 w +S +70 72 m +771.89 72 l +/DeviceRGB CS +1 0 0 SCN +4 w +S +771.89 124.716 m +70 124.716 l +/DeviceRGB CS +1 0 0 SCN +4 w +S 72 72 m -172 272 m -272 272 m -372 272 m +769.89 124.716 m 72 72 m -272 322 m -472 322 m -672 322 m +769.89 164.716 m +[] 0 d +0 j +0 J +/Gs1 gs +70 164.716 m +771.89 164.716 l +/DeviceRGB CS +1 0 0 SCN +4 w +S +771.89 217.432 m +70 217.432 l +/DeviceRGB CS +1 0 0 SCN +4 w +S 72 72 m -172 72 m -372 72 m -572 72 m +769.89 217.432 m 72 72 m -272 122 m -372 122 m -572 122 m +769.89 257.432 m +[] 0 d +0 j +0 J +/Gs1 gs +72 312.148 m +72 255.432 l +/DeviceRGB CS +0 1 0 SCN +4 w +S +769.89 255.432 m +769.89 312.148 l +/DeviceRGB CS +0 1 0 SCN +4 w +S +70 257.432 m +771.89 257.432 l +/DeviceRGB CS +1 0 0 SCN +4 w +S +771.89 310.148 m +70 310.148 l +/DeviceRGB CS +1 0 0 SCN +4 w +S 72 72 m -272 172 m -472 172 m -572 172 m +769.89 310.148 m 72 72 m -238.666667 222 m -405.333333 222 m -572 222 m +769.89 350.148 m +[] 0 d +0 j +0 J +/Gs1 gs +72 404.864 m +72 348.148 l +/DeviceRGB CS +1 1 0 SCN +4 w +S +769.89 348.148 m +769.89 404.864 l +/DeviceRGB CS +0 1 0 SCN +4 w +S +70 350.148 m +771.89 350.148 l +/DeviceRGB CS +1 0 0 SCN +4 w +S +771.89 402.864 m +70 402.864 l +/DeviceRGB CS +0 0 1 SCN +4 w +S 72 72 m -172 272 m -272 272 m -372 272 m +769.89 72 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 366.7095 494.1115 Tm +/F1 11 Tf +[<626f72646572436f6c6f72> -30 <3a> 50 <20222366663030303022> 0] TJ +ET +Q 72 72 m -272 322 m -472 322 m -672 322 m +769.89 124.716 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +72 72 m +769.89 164.716 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 363.6515 401.3955 Tm +/F1 11 Tf +[<626f72646572436f6c6f72> -30 <3a> 50 <205b2223666630303030225d> 0] TJ +ET +Q +72 72 m +769.89 217.432 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +72 72 m +769.89 257.432 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 338.3405 308.6795 Tm +/F1 11 Tf +[<626f72646572436f6c6f72> -30 <3a> 50 <205b2223666630303030222c202223303066663030225d> 0] TJ +ET +Q +72 72 m +769.89 310.148 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +72 72 m +769.89 350.148 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 290.7765 215.9635 Tm +/F1 11 Tf +[<626f72646572436f6c6f72> -30 <3a> 50 <205b2223666630303030222c202223303066663030222c202223303030306666222c202223666666663030225d> 0] TJ +ET +Q ", ] `; @@ -1088,46 +1198,6 @@ BT [<746162> 20 <6c65> 15 <2c2023666630303030> 0] TJ ET Q -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m ", ] `; @@ -1468,85 +1538,35 @@ Q q 1 0 0 -1 0 595.28 cm BT -1 0 0 1 330.65075 445.4695 Tm +1 0 0 1 324.53475 445.4695 Tm /F1 11 Tf -[<31> 0] TJ +[<312c2031> 0] TJ ET Q 595.4175 122 m /DeviceRGB cs 0 0 0 scn -/Gs2 gs -q -1 0 0 -1 0 595.28 cm -BT -1 0 0 1 505.12325 445.4695 Tm -/F1 11 Tf -[<31> 0] TJ -ET -Q -769.89 122 m -/DeviceRGB cs -0 0 0 scn -/Gs2 gs -q -1 0 0 -1 0 595.28 cm -BT -1 0 0 1 661.24775 445.4695 Tm -/F1 11 Tf -[<312c20342c20342c2031> 0] TJ -ET -Q -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 505.12325 445.4695 Tm +/F1 11 Tf +[<31> 0] TJ +ET +Q 769.89 122 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 661.24775 445.4695 Tm +/F1 11 Tf +[<312c20342c20342c2031> 0] TJ +ET +Q 72 184.716 m 304.63 184.716 m 304.63 184.716 m @@ -1821,46 +1841,6 @@ BT [<746162> 20 <6c65> 15 <2c2031> 0] TJ ET Q -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m 72 297.432 m 304.63 297.432 m 304.63 297.432 m @@ -2135,46 +2115,6 @@ BT [<636f6c2c20236666666630302c2023303066666666> 30 <2c2023666630306666> 30 <2c2023666638383030> 0] TJ ET Q -72 297.432 m -304.63 297.432 m -537.26 297.432 m -769.89 297.432 m -72 297.432 m -304.63 347.432 m -537.26 347.432 m -769.89 347.432 m -72 297.432 m -304.63 297.432 m -537.26 297.432 m -769.89 297.432 m -72 297.432 m -304.63 347.432 m -537.26 347.432 m -769.89 347.432 m -72 297.432 m -304.63 297.432 m -537.26 297.432 m -769.89 297.432 m -72 297.432 m -304.63 347.432 m -537.26 347.432 m -769.89 347.432 m -72 297.432 m -304.63 297.432 m -537.26 297.432 m -769.89 297.432 m -72 297.432 m -304.63 347.432 m -537.26 347.432 m -769.89 347.432 m -72 297.432 m -304.63 297.432 m -537.26 297.432 m -769.89 297.432 m -72 297.432 m -304.63 347.432 m -537.26 347.432 m -769.89 347.432 m ", ] `; @@ -2456,46 +2396,6 @@ BT [<746162> 20 <6c65> 15 <2c203138> 0] TJ ET Q -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 102.056 m -537.26 102.056 m -769.89 102.056 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 102.056 m -537.26 102.056 m -769.89 102.056 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 102.056 m -537.26 102.056 m -769.89 102.056 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 102.056 m -537.26 102.056 m -769.89 102.056 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 102.056 m -537.26 102.056 m -769.89 102.056 m ", ] `; @@ -2865,56 +2765,6 @@ BT [<626f74746f6d2072> -15 <69676874> 0] TJ ET Q -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m -72 72 m -246.4725 72 m -420.945 72 m -595.4175 72 m -769.89 72 m -72 72 m -246.4725 122 m -420.945 122 m -595.4175 122 m -769.89 122 m 72 184.716 m 304.63 184.716 m 304.63 184.716 m @@ -3161,74 +3011,34 @@ q 1 0 0 -1 0 595.28 cm BT 1 0 0 1 82 318.6795 Tm -/F1 11 Tf -[<746162> 20 <6c65> 15 <2c203130> 0] TJ -ET -Q -537.26 257.432 m -/DeviceRGB cs -0 0 0 scn -/Gs2 gs -q -1 0 0 -1 0 595.28 cm -BT -1 0 0 1 334.63 298.6795 Tm -/F1 11 Tf -[<636f6c2c203330> 0] TJ -ET -Q -769.89 257.432 m -/DeviceRGB cs -0 0 0 scn -/Gs2 gs -q -1 0 0 -1 0 595.28 cm -BT -1 0 0 1 547.26 318.6795 Tm -/F1 11 Tf -[<746162> 20 <6c65> 15 <2c203130> 0] TJ -ET -Q -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 257.432 m -537.26 257.432 m -769.89 257.432 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 257.432 m -537.26 257.432 m -769.89 257.432 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 257.432 m -537.26 257.432 m -769.89 257.432 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 257.432 m -537.26 257.432 m -769.89 257.432 m -72 184.716 m -304.63 184.716 m -537.26 184.716 m -769.89 184.716 m -72 184.716 m -304.63 257.432 m +/F1 11 Tf +[<746162> 20 <6c65> 15 <2c203130> 0] TJ +ET +Q 537.26 257.432 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 334.63 298.6795 Tm +/F1 11 Tf +[<636f6c2c203330> 0] TJ +ET +Q 769.89 257.432 m +/DeviceRGB cs +0 0 0 scn +/Gs2 gs +q +1 0 0 -1 0 595.28 cm +BT +1 0 0 1 547.26 318.6795 Tm +/F1 11 Tf +[<746162> 20 <6c65> 15 <2c203130> 0] TJ +ET +Q ", ] `; @@ -3647,66 +3457,6 @@ BT [<626f74746f6d2072> -15 <69676874> 0] TJ ET Q -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 172 m -537.26 172 m -769.89 172 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 172 m -537.26 172 m -769.89 172 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 172 m -537.26 172 m -769.89 172 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 172 m -537.26 172 m -769.89 172 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 172 m -537.26 172 m -769.89 172 m 72 234.716 m 304.63 234.716 m 304.63 234.716 m @@ -3981,46 +3731,6 @@ BT [<746162> 20 <6c65> 15 <2c20683a> 50 <2063656e746572> 50 <2c20763a> 50 <2063656e746572> 0] TJ ET Q -72 234.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 234.716 m -304.63 284.716 m -537.26 284.716 m -769.89 284.716 m -72 234.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 234.716 m -304.63 284.716 m -537.26 284.716 m -769.89 284.716 m -72 234.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 234.716 m -304.63 284.716 m -537.26 284.716 m -769.89 284.716 m -72 234.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 234.716 m -304.63 284.716 m -537.26 284.716 m -769.89 284.716 m -72 234.716 m -304.63 234.716 m -537.26 234.716 m -769.89 234.716 m -72 234.716 m -304.63 284.716 m -537.26 284.716 m -769.89 284.716 m ", ] `; @@ -4302,46 +4012,6 @@ BT [<746162> 20 <6c65> 15 <2c2023666630303030> 0] TJ ET Q -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m -72 72 m -304.63 72 m -537.26 72 m -769.89 72 m -72 72 m -304.63 122 m -537.26 122 m -769.89 122 m ", ] `; @@ -4598,56 +4268,6 @@ ET Q 72 72 m 769.89 444.716 m -72 72 m -769.89 72 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -769.89 444.716 m -72 72 m -769.89 72 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -769.89 444.716 m -72 72 m -769.89 72 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -769.89 444.716 m -72 72 m -769.89 72 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -769.89 444.716 m -72 72 m -769.89 72 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -769.89 444.716 m ", "1 0 0 -1 0 595.28 cm 72 72 m @@ -4871,36 +4491,6 @@ BT [<636f6c> 0] TJ ET Q -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m -72 72 m -420.945 84.716 m -769.89 84.716 m -72 72 m -420.945 264.716 m -769.89 264.716 m ", ] `; @@ -4957,16 +4547,6 @@ BT [<31303078313030> 0] TJ ET Q -370.945 247.64 m -470.945 247.64 m -370.945 247.64 m -470.945 247.64 m -370.945 247.64 m -470.945 247.64 m -370.945 247.64 m -470.945 247.64 m -370.945 247.64 m -470.945 247.64 m ", ] `; diff --git a/src/pdf/table.test.ts b/src/pdf/table.test.ts index 40036be..f08d856 100644 --- a/src/pdf/table.test.ts +++ b/src/pdf/table.test.ts @@ -14,13 +14,25 @@ import { paddingOverrides, paddingVariants, singleCell, - textColorOverrides + textColorOverrides, + tupleShorthand } from "swissqrbill:tests:data/table"; import { TestDocument } from "swissqrbill:tests:utils/pdf"; describe("table", async () => { + it("should convert the values of tuples shorthand syntax correctly", async () => { + const pdf = new TestDocument("table/tuple-shorthand.pdf", { layout: "landscape", size: "A4" }); + const table = new Table(tupleShorthand); + + table.attachTo(pdf); + + await pdf.writeFile(); + + expect(pdf.snapshots).toMatchSnapshot(); + }); + it("should render and override background colors correctly", async () => { const pdf = new TestDocument("table/background-color.pdf", { layout: "landscape", size: "A4" }); const table = new Table(backgroundColorOverrides); diff --git a/src/pdf/table.ts b/src/pdf/table.ts index f9b787b..ca47bc6 100644 --- a/src/pdf/table.ts +++ b/src/pdf/table.ts @@ -6,15 +6,15 @@ export interface PDFTable { /** Background color of the table. */ backgroundColor?: string; /** The colors of the border */ - borderColor?: string | [top: string, right?: string, bottom?: string, left?: string]; + borderColor?: PDFBorderColor; /** Width of the borders of the row. */ - borderWidth?: number | [top: number, right?: number, bottom?: number, left?: number]; + borderWidth?: PDFBorderWidth; /** Font of the text inside the table. */ fontName?: string; /** Font size of the text inside the table. */ fontSize?: number; /** Cell padding of the table cells. */ - padding?: number | [top: number, right?: number, bottom?: number, left?: number]; + padding?: PDFPadding; /** Text color of texts inside table. */ textColor?: string; /** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */ @@ -26,6 +26,7 @@ export interface PDFTable { /** Horizontal start position of the table. */ } + export interface PDFRow { /** Table columns. */ columns: PDFColumn[]; @@ -34,9 +35,9 @@ export interface PDFRow { /** Background color of the row. */ backgroundColor?: string; /** The colors of the border */ - borderColor?: string | [top: string, right?: string, bottom?: string, left?: string]; + borderColor?: PDFBorderColor; /** Width of the borders of the row. */ - borderWidth?: number | [top: number, right?: number, bottom?: number, left?: number]; + borderWidth?: PDFBorderWidth; /** Font of the text inside the row. */ fontName?: string; /** Font size of the text inside the row. */ @@ -50,7 +51,7 @@ export interface PDFRow { /** Minimum height of the row */ minHeight?: number; /** Cell padding of the table cells inside the row. */ - padding?: number | [top: number, right?: number, bottom?: number, left?: number]; + padding?: PDFPadding; /** Text color of texts inside the row. */ textColor?: string; /** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */ @@ -67,15 +68,15 @@ export interface PDFColumn { /** Background color of the cell. */ backgroundColor?: string; /** The colors of the border */ - borderColor?: string | [top: string, right?: string, bottom?: string, left?: string]; + borderColor?: PDFBorderColor; /** Width of the borders of the row. */ - borderWidth?: number | [top: number, right?: number, bottom?: number, left?: number]; + borderWidth?: PDFBorderWidth; /** Font of the text inside the cell. */ fontName?: string; /** Font size of the text inside the cell. */ fontSize?: number; /** Cell padding of the table cell. */ - padding?: number | [top: number, right?: number, bottom?: number, left?: number]; + padding?: PDFPadding; /** Text color of texts inside the cell. */ textColor?: string; /** Same as text [PDFKit text options](http://pdfkit.org/docs/text.html#text_styling). */ @@ -86,6 +87,24 @@ export interface PDFColumn { width?: number; } +/** Can be used to set the color of the border of a table, row or column. */ +export type PDFBorderColor = + | string + | [top?: string, right?: string, bottom?: string, left?: string] + | [vertical?: string, horizontal?: string]; + +/** Can be used to set the width of the border of a table, row or column. */ +export type PDFBorderWidth = + | number + | [top?: number, right?: number, bottom?: number, left?: number] + | [vertical?: number, horizontal?: number]; + +/** Can be used to set the padding of a table cell. */ +export type PDFPadding = + | number + | [top?: number, right?: number, bottom?: number, left?: number] + | [vertical?: number, horizontal?: number]; + enum TableLayer { HeightCalculation, PageInjection, @@ -195,9 +214,11 @@ export class Table { const tableAlign = this.data.align ? this.data.align : undefined; const tableVerticalAlign = this.data.verticalAlign ? this.data.verticalAlign : "top"; + const headerRowIndex = this.data.rows.findIndex(row => !!row.header); + const autoRowHeights: number[] = []; - for(let layer: TableLayer = 0; layer < Object.keys(TableLayer).length; layer++){ + for(let layer: TableLayer = 0; layer < Object.values(TableLayer).length / 2; layer++){ // Always start on the first page for each layer doc.switchToPage(startPage); @@ -314,10 +335,10 @@ export class Table { rowY = doc.y; // Insert header - const headerRow = this.data.rows.find(row => row.header); + const headerRow = this.data.rows[headerRowIndex]; if(headerRow !== undefined){ this.data.rows.splice(rowIndex, 0, headerRow); - autoRowHeights.splice(rowIndex, 0, autoRowHeights[this.data.rows.indexOf(headerRow)]); + autoRowHeights.splice(rowIndex, 0, autoRowHeights[headerRowIndex]); rowIndex--; continue rowLoop; } @@ -328,11 +349,11 @@ export class Table { // Switch page before overflowing rows and header rows if(layer > TableLayer.PageInjection){ if( - !!row.header && rowY !== doc.page.margins.top || + !!row.header && rowY !== (doc.page.margins.top ?? 0) && rowIndex !== headerRowIndex || rowY + rowHeight >= doc.page.height - doc.page.margins.bottom ){ doc.switchToPage(this.getCurrentPage(doc) + 1); - doc.x = doc.page.margins.left ?? 0; + doc.x = tableX; doc.y = doc.page.margins.top ?? 0; rowY = doc.y; } @@ -457,7 +478,7 @@ export class Table { } - private _positionsToObject(numberOrPositions: T | [top: T, right?: T, bottom?: T, left?: T]): { bottom?: T; left?: T; right?: T; top?: T; } { + private _positionsToObject(numberOrPositions: T | [top?: T, right?: T, bottom?: T, left?: T]): { bottom?: T; left?: T; right?: T; top?: T; } { if(typeof numberOrPositions === "number" || typeof numberOrPositions === "string"){ return { @@ -468,9 +489,9 @@ export class Table { }; } else { return { - bottom: numberOrPositions[2] ? numberOrPositions[2] : numberOrPositions[0], - left: numberOrPositions[3] ? numberOrPositions[3] : numberOrPositions[1] ? numberOrPositions[1] : numberOrPositions[0], - right: numberOrPositions[1] ? numberOrPositions[1] : numberOrPositions[0], + bottom: numberOrPositions[2] !== undefined ? numberOrPositions[2] : numberOrPositions[0], + left: numberOrPositions[3] !== undefined ? numberOrPositions[3] : numberOrPositions[1], + right: numberOrPositions[1] !== undefined ? numberOrPositions[1] : undefined, top: numberOrPositions[0] }; } diff --git a/tests/data/table.ts b/tests/data/table.ts index b443ccc..b5de0cd 100644 --- a/tests/data/table.ts +++ b/tests/data/table.ts @@ -1,6 +1,59 @@ import type { PDFTable } from "swissqrbill:pdf:table"; +export const tupleShorthand: PDFTable = { + align: "center", + padding: 20, + rows: [ + { + columns: [ + { + borderColor: "#ff0000", + borderWidth: 4, + text: "borderColor: \"#ff0000\"" + } + ] + }, + { + columns: [{ text: "" }] + }, + { + columns: [ + { + borderColor: ["#ff0000"], + borderWidth: 4, + text: "borderColor: [\"#ff0000\"]" + } + ] + }, + { + columns: [{ text: "" }] + }, + { + columns: [ + { + borderColor: ["#ff0000", "#00ff00"], + borderWidth: 4, + text: "borderColor: [\"#ff0000\", \"#00ff00\"]" + } + ] + }, + { + columns: [{ text: "" }] + }, + { + columns: [ + { + borderColor: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"], + borderWidth: 4, + text: "borderColor: [\"#ff0000\", \"#00ff00\", \"#0000ff\", \"#ffff00\"]" + } + ] + } + ], + verticalAlign: "center" +}; + export const backgroundColorOverrides: PDFTable = { align: "center", backgroundColor: "#ff0000", @@ -214,8 +267,8 @@ export const borderThickness: PDFTable = { }, { align: "center", - borderWidth: [1], - text: "1", + borderWidth: [1, 1], + text: "1, 1", verticalAlign: "center" }, {