diff --git a/spec/context2d.spec.js b/spec/context2d.spec.js index 4fa0f6cfe..4a8cc59d7 100644 --- a/spec/context2d.spec.js +++ b/spec/context2d.spec.js @@ -513,4 +513,16 @@ describe("Context2D: standard tests", () => { y += 40 + pad; comparePdf(doc.output(), "textBaseline.pdf", "context2d"); }); + + it("autoPaging with 10 or more pages", () => { + const doc = new jsPDF({ format: [100, 100], floatPrecision: 2 }); + const ctx = doc.context2d; + ctx.autoPaging = true; + ctx.fillStyle = "red"; + ctx.fillRect(0, 750, 20, 100); // rectangle starting from page 8 going to page 9 + ctx.fillStyle = "blue"; + ctx.fillRect(0, 850, 20, 100); // rectangle starting from page 9 going to page 10 + + comparePdf(doc.output(), "autoPaging10Pages.pdf", "context2d"); + }); }); diff --git a/spec/reference/autoPaging10Pages.pdf b/spec/reference/autoPaging10Pages.pdf new file mode 100644 index 000000000..8e63ccfff Binary files /dev/null and b/spec/reference/autoPaging10Pages.pdf differ diff --git a/src/modules/context2d.js b/src/modules/context2d.js index c598b804b..b7bbb8435 100644 --- a/src/modules/context2d.js +++ b/src/modules/context2d.js @@ -1441,7 +1441,7 @@ } } - pages.sort(); + sortPages(pages); var clipPath; if (this.autoPaging) { @@ -1595,6 +1595,12 @@ return paths; }; + var sortPages = function (pages) { + return pages.sort(function (a, b) { + return a - b; + }) + } + var pathPreProcess = function(rule, isClip) { var fillStyle = this.fillStyle; var strokeStyle = this.strokeStyle; @@ -1625,7 +1631,7 @@ addPage.call(this); } } - pages.sort(); + sortPages(pages); if (this.autoPaging) { var min = pages[0]; @@ -1987,7 +1993,7 @@ } } - pages.sort(); + sortPages(pages); var clipPath, oldSize; if (this.autoPaging === true) {