From b096a5134ae7bd52f89b7f3fcf4b8cc6c5ece929 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?=
<42278642+schoero@users.noreply.github.com>
Date: Thu, 16 Nov 2023 20:16:31 +0100
Subject: [PATCH 1/6] fix(table): throwing error when header row was enabled on
a table with multiple columns
---
src/pdf/table.ts | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/pdf/table.ts b/src/pdf/table.ts
index f9b787b..cb90988 100644
--- a/src/pdf/table.ts
+++ b/src/pdf/table.ts
@@ -195,6 +195,8 @@ 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++){
@@ -314,10 +316,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,7 +330,7 @@ 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);
From 14ad3c3d0a287bfd2226ce2ac7e8e02f1a578f87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?=
<42278642+schoero@users.noreply.github.com>
Date: Thu, 16 Nov 2023 20:17:22 +0100
Subject: [PATCH 2/6] fix(table): setting padding to `0` not working in a tuple
type
---
src/pdf/table.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/pdf/table.ts b/src/pdf/table.ts
index cb90988..595f73f 100644
--- a/src/pdf/table.ts
+++ b/src/pdf/table.ts
@@ -470,9 +470,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] ?? numberOrPositions[0],
+ left: numberOrPositions[3] !== undefined ? numberOrPositions[3] : numberOrPositions[1] ?? numberOrPositions[0],
+ right: numberOrPositions[1] !== undefined ? numberOrPositions[1] : numberOrPositions[0] ?? numberOrPositions[0],
top: numberOrPositions[0]
};
}
From e8e5aec8a134ebcfa7aa224a97136557fafc9046 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?=
<42278642+schoero@users.noreply.github.com>
Date: Thu, 16 Nov 2023 20:17:44 +0100
Subject: [PATCH 3/6] fix(table): continue table on the same horizontal
position
---
src/pdf/table.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/pdf/table.ts b/src/pdf/table.ts
index 595f73f..2d88285 100644
--- a/src/pdf/table.ts
+++ b/src/pdf/table.ts
@@ -334,7 +334,7 @@ export class Table {
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;
}
From 9eb4f3d42541af74edd4b1eb4fd3f26f32dc11c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?=
<42278642+schoero@users.noreply.github.com>
Date: Thu, 16 Nov 2023 20:18:44 +0100
Subject: [PATCH 4/6] fix(table): rendering of imaginary layers
---
src/pdf/table.test.snap | 702 ++--------------------------------------
src/pdf/table.ts | 2 +-
2 files changed, 27 insertions(+), 677 deletions(-)
diff --git a/src/pdf/table.test.snap b/src/pdf/table.test.snap
index 18010ac..458aa6c 100644
--- a/src/pdf/table.test.snap
+++ b/src/pdf/table.test.snap
@@ -825,126 +825,6 @@ BT
[<323030> 0] TJ
ET
Q
-72 72 m
-172 72 m
-372 72 m
-572 72 m
-72 72 m
-272 122 m
-372 122 m
-572 122 m
-72 72 m
-272 172 m
-472 172 m
-572 172 m
-72 72 m
-238.666667 222 m
-405.333333 222 m
-572 222 m
-72 72 m
-172 272 m
-272 272 m
-372 272 m
-72 72 m
-272 322 m
-472 322 m
-672 322 m
-72 72 m
-172 72 m
-372 72 m
-572 72 m
-72 72 m
-272 122 m
-372 122 m
-572 122 m
-72 72 m
-272 172 m
-472 172 m
-572 172 m
-72 72 m
-238.666667 222 m
-405.333333 222 m
-572 222 m
-72 72 m
-172 272 m
-272 272 m
-372 272 m
-72 72 m
-272 322 m
-472 322 m
-672 322 m
-72 72 m
-172 72 m
-372 72 m
-572 72 m
-72 72 m
-272 122 m
-372 122 m
-572 122 m
-72 72 m
-272 172 m
-472 172 m
-572 172 m
-72 72 m
-238.666667 222 m
-405.333333 222 m
-572 222 m
-72 72 m
-172 272 m
-272 272 m
-372 272 m
-72 72 m
-272 322 m
-472 322 m
-672 322 m
-72 72 m
-172 72 m
-372 72 m
-572 72 m
-72 72 m
-272 122 m
-372 122 m
-572 122 m
-72 72 m
-272 172 m
-472 172 m
-572 172 m
-72 72 m
-238.666667 222 m
-405.333333 222 m
-572 222 m
-72 72 m
-172 272 m
-272 272 m
-372 272 m
-72 72 m
-272 322 m
-472 322 m
-672 322 m
-72 72 m
-172 72 m
-372 72 m
-572 72 m
-72 72 m
-272 122 m
-372 122 m
-572 122 m
-72 72 m
-272 172 m
-472 172 m
-572 172 m
-72 72 m
-238.666667 222 m
-405.333333 222 m
-572 222 m
-72 72 m
-172 272 m
-272 272 m
-372 272 m
-72 72 m
-272 322 m
-472 322 m
-672 322 m
",
]
`;
@@ -1088,46 +968,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
",
]
`;
@@ -1497,56 +1337,6 @@ BT
[<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
-769.89 122 m
72 184.716 m
304.63 184.716 m
304.63 184.716 m
@@ -1821,46 +1611,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 +1885,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 +2166,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 +2535,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 +2781,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 +3227,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 +3501,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 +3782,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 +4038,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 +4261,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 +4317,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.ts b/src/pdf/table.ts
index 2d88285..bf07b52 100644
--- a/src/pdf/table.ts
+++ b/src/pdf/table.ts
@@ -199,7 +199,7 @@ export class Table {
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);
From 99b1c954e0c8c68f7ff76c442c57d1348601d184 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?=
<42278642+schoero@users.noreply.github.com>
Date: Thu, 16 Nov 2023 21:03:21 +0100
Subject: [PATCH 5/6] fix(table): converting of tuple shorthand syntax
---
docs/bundle/index.md | 175 ++++++++++++++----------------
docs/pdf/index.md | 179 +++++++++++++++---------------
src/pdf/table.test.snap | 234 +++++++++++++++++++++++++++++++++++++++-
src/pdf/table.test.ts | 14 ++-
src/pdf/table.ts | 42 +++++---
tests/data/table.ts | 57 +++++++++-
6 files changed, 497 insertions(+), 204 deletions(-)
diff --git a/docs/bundle/index.md b/docs/bundle/index.md
index 47d5c26..5f7c9b3 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,95 @@ 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#L90C0)
- - [`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)
+
+
+
+#### Type alias: pdf.PDFBorderWidth
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L95C0)
+
+##### 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)
+
+
+
+#### Type alias: pdf.PDFPadding
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L100C0)
+
+##### 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)
#### Class: pdf.Table
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L138C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L154C0)
##### Description
@@ -516,7 +507,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#L161C2)
###### Parameter
@@ -536,7 +527,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#L185C2)
###### Parameters
diff --git a/docs/pdf/index.md b/docs/pdf/index.md
index 4281078..9bd09f3 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#L154C0)
#### 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#L161C2)
##### 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#L185C2)
##### Parameters
@@ -329,48 +332,90 @@ 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#L90C0)
-- **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`
+
+ - 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)
- - [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- - `tuple`
+- `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)
+ - 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)
-- **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`
+### Type alias: PDFBorderWidth
- - 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)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L95C0)
-- **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
+
+`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`
- - [`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)
- - 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)
+
+
+### Type alias: PDFPadding
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L100C0)
+
+#### 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)
+
+
+
+### Interface: PDFTable
+
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L1C0)
+
+- **rows** [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Table rows.
+
+ - [`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 +425,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 +433,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 +450,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 458aa6c..1de534f 100644
--- a/src/pdf/table.test.snap
+++ b/src/pdf/table.test.snap
@@ -829,6 +829,236 @@ Q
]
`;
+exports[`table > should convert the values of tuples shorthand syntax correctly 1`] = `
+[
+ "1 0 0 -1 0 595.28 cm
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 124.716 m
+72 72 m
+769.89 164.716 m
+72 72 m
+769.89 217.432 m
+72 72 m
+769.89 257.432 m
+72 72 m
+769.89 310.148 m
+72 72 m
+769.89 350.148 m
+72 72 m
+769.89 72 m
+72 72 m
+769.89 124.716 m
+72 72 m
+769.89 164.716 m
+72 72 m
+769.89 217.432 m
+72 72 m
+769.89 257.432 m
+72 72 m
+769.89 310.148 m
+72 72 m
+769.89 350.148 m
+72 72 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
+769.89 124.716 m
+72 72 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
+769.89 217.432 m
+72 72 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
+769.89 310.148 m
+72 72 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
+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
+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
+",
+]
+`;
+
exports[`table > should render and override background colors correctly 1`] = `
[
"1 0 0 -1 0 595.28 cm
@@ -1308,9 +1538,9 @@ 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
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 bf07b52..6be5dce 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,21 @@ export interface PDFColumn {
width?: number;
}
+export type PDFBorderColor =
+ | string
+ | [top?: string, right?: string, bottom?: string, left?: string]
+ | [vertical?: string, horizontal?: string];
+
+export type PDFBorderWidth =
+ | number
+ | [top?: number, right?: number, bottom?: number, left?: number]
+ | [vertical?: number, horizontal?: number];
+
+export type PDFPadding =
+ | number
+ | [top?: number, right?: number, bottom?: number, left?: number]
+ | [vertical?: number, horizontal?: number];
+
enum TableLayer {
HeightCalculation,
PageInjection,
@@ -459,7 +475,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 {
@@ -470,9 +486,9 @@ export class Table {
};
} else {
return {
- bottom: numberOrPositions[2] !== undefined ? numberOrPositions[2] : numberOrPositions[0] ?? numberOrPositions[0],
- left: numberOrPositions[3] !== undefined ? numberOrPositions[3] : numberOrPositions[1] ?? numberOrPositions[0],
- right: numberOrPositions[1] !== undefined ? numberOrPositions[1] : numberOrPositions[0] ?? 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"
},
{
From 082d9ed78ea53bfc3fddd526bf67bc8aa8962dd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?=
<42278642+schoero@users.noreply.github.com>
Date: Thu, 16 Nov 2023 21:07:47 +0100
Subject: [PATCH 6/6] docs: add description
---
docs/bundle/index.md | 24 ++++++++++++++++++------
docs/pdf/index.md | 24 ++++++++++++++++++------
src/pdf/table.ts | 3 +++
3 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/docs/bundle/index.md b/docs/bundle/index.md
index 5f7c9b3..7ecf27e 100644
--- a/docs/bundle/index.md
+++ b/docs/bundle/index.md
@@ -388,7 +388,7 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L63C0)
#### Type alias: pdf.PDFBorderColor
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L90C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L91C0)
##### Type
@@ -407,11 +407,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L90C0)
- 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#L95C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L97C0)
##### Type
@@ -430,11 +434,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L95C0)
- 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#L100C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L103C0)
##### Type
@@ -453,11 +461,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L100C0)
- 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#L154C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L157C0)
##### Description
@@ -507,7 +519,7 @@ pdf.end();
##### Constructor: new pdf.Table(data)
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L161C2)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L164C2)
###### Parameter
@@ -527,7 +539,7 @@ Creates a new Table instance.
`public`
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L185C2)
+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 9bd09f3..cc8ec6e 100644
--- a/docs/pdf/index.md
+++ b/docs/pdf/index.md
@@ -239,7 +239,7 @@ Attaches the Swiss QR Code to a PDF document.
### Class: Table
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L154C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L157C0)
#### Description
@@ -289,7 +289,7 @@ pdf.end();
#### Constructor: new Table(data)
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L161C2)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L164C2)
##### Parameter
@@ -309,7 +309,7 @@ Creates a new Table instance.
`public`
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L185C2)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L188C2)
##### Parameters
@@ -334,7 +334,7 @@ every row that no longer fits on a page.
### Type alias: PDFBorderColor
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L90C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L91C0)
#### Type
@@ -353,11 +353,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L90C0)
- 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: PDFBorderWidth
-Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L95C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L97C0)
#### Type
@@ -376,11 +380,15 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L95C0)
- 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#L100C0)
+Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L103C0)
#### Type
@@ -399,6 +407,10 @@ Defined in: [src/pdf/table.ts](../../src/pdf/table.ts#L100C0)
- 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
diff --git a/src/pdf/table.ts b/src/pdf/table.ts
index 6be5dce..ca47bc6 100644
--- a/src/pdf/table.ts
+++ b/src/pdf/table.ts
@@ -87,16 +87,19 @@ 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]