Skip to content

Commit 6181713

Browse files
3.8.0
1 parent c0d1d15 commit 6181713

File tree

6 files changed

+163
-60
lines changed

6 files changed

+163
-60
lines changed

dist/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface Settings {
103103
tableLineWidth: number;
104104
tableLineColor: Color;
105105
horizontalPageBreak?: boolean;
106+
horizontalPageBreakBehaviour?: "immediately" | "afterAllRows";
106107
horizontalPageBreakRepeat?: string | number | string[] | number[] | null;
107108
}
108109
export interface StylesProps {
@@ -239,6 +240,7 @@ export type RowPageBreakType = "auto" | "avoid";
239240
export type TableWidthType = "auto" | "wrap" | number;
240241
export type ShowHeadType = "everyPage" | "firstPage" | "never" | boolean;
241242
export type ShowFootType = "everyPage" | "lastPage" | "never" | boolean;
243+
export type HorizontalPageBreakBehaviourType = "immediately" | "afterAllRows";
242244
export interface UserOptions {
243245
includeHiddenHtml?: boolean;
244246
useCss?: boolean;
@@ -260,6 +262,7 @@ export interface UserOptions {
260262
columns?: ColumnInput[];
261263
horizontalPageBreak?: boolean;
262264
horizontalPageBreakRepeat?: string[] | number[] | string | number;
265+
horizontalPageBreakBehaviour?: HorizontalPageBreakBehaviourType;
263266
styles?: Partial<Styles>;
264267
bodyStyles?: Partial<Styles>;
265268
headStyles?: Partial<Styles>;

dist/jspdf.plugin.autotable.js

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
*
3-
* jsPDF AutoTable plugin v3.7.1
3+
* jsPDF AutoTable plugin v3.8.0
44
*
55
* Copyright (c) 2023 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable
66
* Licensed under the MIT License.
@@ -933,7 +933,7 @@ function parseHooks(global, document, current) {
933933
return result;
934934
}
935935
function parseSettings(doc, options) {
936-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
936+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
937937
var margin = (0, common_1.parseSpacing)(options.margin, 40 / doc.scaleFactor());
938938
var startY = (_a = getStartY(doc, options.startY)) !== null && _a !== void 0 ? _a : margin.top;
939939
var showFoot;
@@ -958,9 +958,7 @@ function parseSettings(doc, options) {
958958
}
959959
var useCss = (_d = options.useCss) !== null && _d !== void 0 ? _d : false;
960960
var theme = options.theme || (useCss ? 'plain' : 'striped');
961-
var horizontalPageBreak = options.horizontalPageBreak
962-
? true
963-
: false;
961+
var horizontalPageBreak = !!options.horizontalPageBreak;
964962
var horizontalPageBreakRepeat = (_e = options.horizontalPageBreakRepeat) !== null && _e !== void 0 ? _e : null;
965963
return {
966964
includeHiddenHtml: (_f = options.includeHiddenHtml) !== null && _f !== void 0 ? _f : false,
@@ -977,6 +975,7 @@ function parseSettings(doc, options) {
977975
tableLineColor: (_l = options.tableLineColor) !== null && _l !== void 0 ? _l : 200,
978976
horizontalPageBreak: horizontalPageBreak,
979977
horizontalPageBreakRepeat: horizontalPageBreakRepeat,
978+
horizontalPageBreakBehaviour: (_m = options.horizontalPageBreakBehaviour) !== null && _m !== void 0 ? _m : 'afterAllRows',
980979
};
981980
}
982981
function getStartY(doc, userStartY) {
@@ -1681,20 +1680,55 @@ exports.drawTable = drawTable;
16811680
function printTableWithHorizontalPageBreak(doc, table, startPos, cursor) {
16821681
// calculate width of columns and render only those which can fit into page
16831682
var allColumnsCanFitResult = (0, tablePrinter_1.calculateAllColumnsCanFitInPage)(doc, table);
1684-
allColumnsCanFitResult.map(function (colsAndIndexes, index) {
1685-
doc.applyStyles(doc.userStyles);
1686-
// add page to print next columns in new page
1687-
if (index > 0) {
1688-
addPage(doc, table, startPos, cursor, colsAndIndexes.columns);
1689-
}
1690-
else {
1691-
// print head for selected columns
1692-
printHead(doc, table, cursor, colsAndIndexes.columns);
1683+
var settings = table.settings;
1684+
if (settings.horizontalPageBreakBehaviour === 'afterAllRows') {
1685+
allColumnsCanFitResult.forEach(function (colsAndIndexes, index) {
1686+
doc.applyStyles(doc.userStyles);
1687+
// add page to print next columns in new page
1688+
if (index > 0) {
1689+
addPage(doc, table, startPos, cursor, colsAndIndexes.columns);
1690+
}
1691+
else {
1692+
// print head for selected columns
1693+
printHead(doc, table, cursor, colsAndIndexes.columns);
1694+
}
1695+
// print body & footer for selected columns
1696+
printBody(doc, table, startPos, cursor, colsAndIndexes.columns);
1697+
printFoot(doc, table, cursor, colsAndIndexes.columns);
1698+
});
1699+
}
1700+
else {
1701+
var lastRowIndexOfLastPage_1 = -1;
1702+
var firstColumnsToFitResult = allColumnsCanFitResult[0];
1703+
var _loop_1 = function () {
1704+
// Print the first columns, taking note of the last row printed
1705+
var lastPrintedRowIndex = lastRowIndexOfLastPage_1;
1706+
if (firstColumnsToFitResult) {
1707+
doc.applyStyles(doc.userStyles);
1708+
if (lastRowIndexOfLastPage_1 >= 0) {
1709+
addPage(doc, table, startPos, cursor, firstColumnsToFitResult.columns);
1710+
}
1711+
else {
1712+
printHead(doc, table, cursor, firstColumnsToFitResult.columns);
1713+
}
1714+
lastPrintedRowIndex = printBodyWithoutPageBreaks(doc, table, lastRowIndexOfLastPage_1 + 1, cursor, firstColumnsToFitResult.columns);
1715+
printFoot(doc, table, cursor, firstColumnsToFitResult.columns);
1716+
}
1717+
// Check how many rows were printed, so that the next columns would not print more rows than that
1718+
var maxNumberOfRows = lastPrintedRowIndex - lastRowIndexOfLastPage_1;
1719+
// Print the next columns, never exceding maxNumberOfRows
1720+
allColumnsCanFitResult.slice(1).forEach(function (colsAndIndexes) {
1721+
doc.applyStyles(doc.userStyles);
1722+
addPage(doc, table, startPos, cursor, colsAndIndexes.columns);
1723+
printBodyWithoutPageBreaks(doc, table, lastRowIndexOfLastPage_1 + 1, cursor, colsAndIndexes.columns, maxNumberOfRows);
1724+
printFoot(doc, table, cursor, colsAndIndexes.columns);
1725+
});
1726+
lastRowIndexOfLastPage_1 = lastPrintedRowIndex;
1727+
};
1728+
while (lastRowIndexOfLastPage_1 < table.body.length - 1) {
1729+
_loop_1();
16931730
}
1694-
// print body & footer for selected columns
1695-
printBody(doc, table, startPos, cursor, colsAndIndexes.columns);
1696-
printFoot(doc, table, cursor, colsAndIndexes.columns);
1697-
});
1731+
}
16981732
}
16991733
function printHead(doc, table, cursor, columns) {
17001734
var settings = table.settings;
@@ -1710,6 +1744,21 @@ function printBody(doc, table, startPos, cursor, columns) {
17101744
printFullRow(doc, table, row, isLastRow, startPos, cursor, columns);
17111745
});
17121746
}
1747+
function printBodyWithoutPageBreaks(doc, table, startRowIndex, cursor, columns, maxNumberOfRows) {
1748+
doc.applyStyles(doc.userStyles);
1749+
maxNumberOfRows = maxNumberOfRows !== null && maxNumberOfRows !== void 0 ? maxNumberOfRows : table.body.length;
1750+
var endRowIndex = Math.min(startRowIndex + maxNumberOfRows, table.body.length);
1751+
var lastPrintedRowIndex = -1;
1752+
table.body.slice(startRowIndex, endRowIndex).forEach(function (row, index) {
1753+
var isLastRow = startRowIndex + index === table.body.length - 1;
1754+
var remainingSpace = getRemainingPageSpace(doc, table, isLastRow, cursor);
1755+
if (row.canEntireRowFit(remainingSpace, columns)) {
1756+
printRow(doc, table, row, cursor, columns);
1757+
lastPrintedRowIndex = startRowIndex + index;
1758+
}
1759+
});
1760+
return lastPrintedRowIndex;
1761+
}
17131762
function printFoot(doc, table, cursor, columns) {
17141763
var settings = table.settings;
17151764
doc.applyStyles(doc.userStyles);
@@ -1815,19 +1864,20 @@ function shouldPrintOnCurrentPage(doc, row, remainingPageSpace, table) {
18151864
function printFullRow(doc, table, row, isLastRow, startPos, cursor, columns) {
18161865
var remainingSpace = getRemainingPageSpace(doc, table, isLastRow, cursor);
18171866
if (row.canEntireRowFit(remainingSpace, columns)) {
1867+
// The row fits in the current page
1868+
printRow(doc, table, row, cursor, columns);
1869+
}
1870+
else if (shouldPrintOnCurrentPage(doc, row, remainingSpace, table)) {
1871+
// The row gets split in two here, each piece in one page
1872+
var remainderRow = modifyRowToFit(row, remainingSpace, table, doc);
18181873
printRow(doc, table, row, cursor, columns);
1874+
addPage(doc, table, startPos, cursor, columns);
1875+
printFullRow(doc, table, remainderRow, isLastRow, startPos, cursor, columns);
18191876
}
18201877
else {
1821-
if (shouldPrintOnCurrentPage(doc, row, remainingSpace, table)) {
1822-
var remainderRow = modifyRowToFit(row, remainingSpace, table, doc);
1823-
printRow(doc, table, row, cursor, columns);
1824-
addPage(doc, table, startPos, cursor, columns);
1825-
printFullRow(doc, table, remainderRow, isLastRow, startPos, cursor, columns);
1826-
}
1827-
else {
1828-
addPage(doc, table, startPos, cursor, columns);
1829-
printFullRow(doc, table, row, isLastRow, startPos, cursor, columns);
1830-
}
1878+
// The row get printed entirelly on the next page
1879+
addPage(doc, table, startPos, cursor, columns);
1880+
printFullRow(doc, table, row, isLastRow, startPos, cursor, columns);
18311881
}
18321882
}
18331883
function printRow(doc, table, row, cursor, columns) {

dist/jspdf.plugin.autotable.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.plugin.autotable.mjs

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ function parseHooks(global, document, current) {
842842
return result;
843843
}
844844
function parseSettings(doc, options) {
845-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
845+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
846846
var margin = parseSpacing(options.margin, 40 / doc.scaleFactor());
847847
var startY = (_a = getStartY(doc, options.startY)) !== null && _a !== void 0 ? _a : margin.top;
848848
var showFoot;
@@ -867,9 +867,7 @@ function parseSettings(doc, options) {
867867
}
868868
var useCss = (_d = options.useCss) !== null && _d !== void 0 ? _d : false;
869869
var theme = options.theme || (useCss ? 'plain' : 'striped');
870-
var horizontalPageBreak = options.horizontalPageBreak
871-
? true
872-
: false;
870+
var horizontalPageBreak = !!options.horizontalPageBreak;
873871
var horizontalPageBreakRepeat = (_e = options.horizontalPageBreakRepeat) !== null && _e !== void 0 ? _e : null;
874872
return {
875873
includeHiddenHtml: (_f = options.includeHiddenHtml) !== null && _f !== void 0 ? _f : false,
@@ -886,6 +884,7 @@ function parseSettings(doc, options) {
886884
tableLineColor: (_l = options.tableLineColor) !== null && _l !== void 0 ? _l : 200,
887885
horizontalPageBreak: horizontalPageBreak,
888886
horizontalPageBreakRepeat: horizontalPageBreakRepeat,
887+
horizontalPageBreakBehaviour: (_m = options.horizontalPageBreakBehaviour) !== null && _m !== void 0 ? _m : 'afterAllRows',
889888
};
890889
}
891890
function getStartY(doc, userStartY) {
@@ -1329,20 +1328,55 @@ function drawTable(jsPDFDoc, table) {
13291328
function printTableWithHorizontalPageBreak(doc, table, startPos, cursor) {
13301329
// calculate width of columns and render only those which can fit into page
13311330
var allColumnsCanFitResult = calculateAllColumnsCanFitInPage(doc, table);
1332-
allColumnsCanFitResult.map(function (colsAndIndexes, index) {
1333-
doc.applyStyles(doc.userStyles);
1334-
// add page to print next columns in new page
1335-
if (index > 0) {
1336-
addPage(doc, table, startPos, cursor, colsAndIndexes.columns);
1337-
}
1338-
else {
1339-
// print head for selected columns
1340-
printHead(doc, table, cursor, colsAndIndexes.columns);
1331+
var settings = table.settings;
1332+
if (settings.horizontalPageBreakBehaviour === 'afterAllRows') {
1333+
allColumnsCanFitResult.forEach(function (colsAndIndexes, index) {
1334+
doc.applyStyles(doc.userStyles);
1335+
// add page to print next columns in new page
1336+
if (index > 0) {
1337+
addPage(doc, table, startPos, cursor, colsAndIndexes.columns);
1338+
}
1339+
else {
1340+
// print head for selected columns
1341+
printHead(doc, table, cursor, colsAndIndexes.columns);
1342+
}
1343+
// print body & footer for selected columns
1344+
printBody(doc, table, startPos, cursor, colsAndIndexes.columns);
1345+
printFoot(doc, table, cursor, colsAndIndexes.columns);
1346+
});
1347+
}
1348+
else {
1349+
var lastRowIndexOfLastPage_1 = -1;
1350+
var firstColumnsToFitResult = allColumnsCanFitResult[0];
1351+
var _loop_1 = function () {
1352+
// Print the first columns, taking note of the last row printed
1353+
var lastPrintedRowIndex = lastRowIndexOfLastPage_1;
1354+
if (firstColumnsToFitResult) {
1355+
doc.applyStyles(doc.userStyles);
1356+
if (lastRowIndexOfLastPage_1 >= 0) {
1357+
addPage(doc, table, startPos, cursor, firstColumnsToFitResult.columns);
1358+
}
1359+
else {
1360+
printHead(doc, table, cursor, firstColumnsToFitResult.columns);
1361+
}
1362+
lastPrintedRowIndex = printBodyWithoutPageBreaks(doc, table, lastRowIndexOfLastPage_1 + 1, cursor, firstColumnsToFitResult.columns);
1363+
printFoot(doc, table, cursor, firstColumnsToFitResult.columns);
1364+
}
1365+
// Check how many rows were printed, so that the next columns would not print more rows than that
1366+
var maxNumberOfRows = lastPrintedRowIndex - lastRowIndexOfLastPage_1;
1367+
// Print the next columns, never exceding maxNumberOfRows
1368+
allColumnsCanFitResult.slice(1).forEach(function (colsAndIndexes) {
1369+
doc.applyStyles(doc.userStyles);
1370+
addPage(doc, table, startPos, cursor, colsAndIndexes.columns);
1371+
printBodyWithoutPageBreaks(doc, table, lastRowIndexOfLastPage_1 + 1, cursor, colsAndIndexes.columns, maxNumberOfRows);
1372+
printFoot(doc, table, cursor, colsAndIndexes.columns);
1373+
});
1374+
lastRowIndexOfLastPage_1 = lastPrintedRowIndex;
1375+
};
1376+
while (lastRowIndexOfLastPage_1 < table.body.length - 1) {
1377+
_loop_1();
13411378
}
1342-
// print body & footer for selected columns
1343-
printBody(doc, table, startPos, cursor, colsAndIndexes.columns);
1344-
printFoot(doc, table, cursor, colsAndIndexes.columns);
1345-
});
1379+
}
13461380
}
13471381
function printHead(doc, table, cursor, columns) {
13481382
var settings = table.settings;
@@ -1358,6 +1392,21 @@ function printBody(doc, table, startPos, cursor, columns) {
13581392
printFullRow(doc, table, row, isLastRow, startPos, cursor, columns);
13591393
});
13601394
}
1395+
function printBodyWithoutPageBreaks(doc, table, startRowIndex, cursor, columns, maxNumberOfRows) {
1396+
doc.applyStyles(doc.userStyles);
1397+
maxNumberOfRows = maxNumberOfRows !== null && maxNumberOfRows !== void 0 ? maxNumberOfRows : table.body.length;
1398+
var endRowIndex = Math.min(startRowIndex + maxNumberOfRows, table.body.length);
1399+
var lastPrintedRowIndex = -1;
1400+
table.body.slice(startRowIndex, endRowIndex).forEach(function (row, index) {
1401+
var isLastRow = startRowIndex + index === table.body.length - 1;
1402+
var remainingSpace = getRemainingPageSpace(doc, table, isLastRow, cursor);
1403+
if (row.canEntireRowFit(remainingSpace, columns)) {
1404+
printRow(doc, table, row, cursor, columns);
1405+
lastPrintedRowIndex = startRowIndex + index;
1406+
}
1407+
});
1408+
return lastPrintedRowIndex;
1409+
}
13611410
function printFoot(doc, table, cursor, columns) {
13621411
var settings = table.settings;
13631412
doc.applyStyles(doc.userStyles);
@@ -1463,19 +1512,20 @@ function shouldPrintOnCurrentPage(doc, row, remainingPageSpace, table) {
14631512
function printFullRow(doc, table, row, isLastRow, startPos, cursor, columns) {
14641513
var remainingSpace = getRemainingPageSpace(doc, table, isLastRow, cursor);
14651514
if (row.canEntireRowFit(remainingSpace, columns)) {
1515+
// The row fits in the current page
1516+
printRow(doc, table, row, cursor, columns);
1517+
}
1518+
else if (shouldPrintOnCurrentPage(doc, row, remainingSpace, table)) {
1519+
// The row gets split in two here, each piece in one page
1520+
var remainderRow = modifyRowToFit(row, remainingSpace, table, doc);
14661521
printRow(doc, table, row, cursor, columns);
1522+
addPage(doc, table, startPos, cursor, columns);
1523+
printFullRow(doc, table, remainderRow, isLastRow, startPos, cursor, columns);
14671524
}
14681525
else {
1469-
if (shouldPrintOnCurrentPage(doc, row, remainingSpace, table)) {
1470-
var remainderRow = modifyRowToFit(row, remainingSpace, table, doc);
1471-
printRow(doc, table, row, cursor, columns);
1472-
addPage(doc, table, startPos, cursor, columns);
1473-
printFullRow(doc, table, remainderRow, isLastRow, startPos, cursor, columns);
1474-
}
1475-
else {
1476-
addPage(doc, table, startPos, cursor, columns);
1477-
printFullRow(doc, table, row, isLastRow, startPos, cursor, columns);
1478-
}
1526+
// The row get printed entirelly on the next page
1527+
addPage(doc, table, startPos, cursor, columns);
1528+
printFullRow(doc, table, row, isLastRow, startPos, cursor, columns);
14791529
}
14801530
}
14811531
function printRow(doc, table, row, cursor, columns) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspdf-autotable",
3-
"version": "3.7.1",
3+
"version": "3.8.0",
44
"description": "Generate pdf tables with javascript (jsPDF plugin)",
55
"main": "dist/jspdf.plugin.autotable.js",
66
"exports": {

0 commit comments

Comments
 (0)