From ee7208b4ea01443115092730203ce637122682f1 Mon Sep 17 00:00:00 2001 From: Jake Holland Date: Wed, 5 Feb 2025 10:49:58 +0000 Subject: [PATCH] Fix page cascade options when text overflows (#1597) --- CHANGELOG.md | 1 + lib/document.js | 2 +- lib/page.js | 1 + tests/unit/page.spec.js | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/unit/page.spec.js diff --git a/CHANGELOG.md b/CHANGELOG.md index ceea272e..0c1cbb2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix fonts without a postscriptName - Add support for dynamic sizing - Add support for rotatable text +- Fix page cascade options when text overflows ### [v0.16.0] - 2024-12-29 diff --git a/lib/document.js b/lib/document.js index 6afab490..1a341460 100644 --- a/lib/document.js +++ b/lib/document.js @@ -169,7 +169,7 @@ class PDFDocument extends stream.Readable { continueOnNewPage(options) { const pageMarkings = this.endPageMarkings(this.page); - this.addPage(options); + this.addPage(options ?? this.page._options); this.initPageMarkings(pageMarkings); diff --git a/lib/page.js b/lib/page.js index dcea632d..7df6609a 100644 --- a/lib/page.js +++ b/lib/page.js @@ -71,6 +71,7 @@ const SIZES = { class PDFPage { constructor(document, options = {}) { this.document = document; + this._options = options; this.size = options.size || 'letter'; this.layout = options.layout || 'portrait'; diff --git a/tests/unit/page.spec.js b/tests/unit/page.spec.js new file mode 100644 index 00000000..ceb7ca70 --- /dev/null +++ b/tests/unit/page.spec.js @@ -0,0 +1,16 @@ +import PDFDocument from '../../lib/document'; + +describe('page', function () { + test('cascade page options', function () { + const doc = new PDFDocument({ + autoFirstPage: false, + bufferPages: true, + }); + doc.addPage({ size: [50, 50], margin: 0 }); + doc.text(Array(10).fill('TEST').join('\n')); + doc._pageBuffer.forEach((page) => { + expect(page.size).toEqual([50, 50]); + expect(page.margins).toEqual({ top: 0, right: 0, bottom: 0, left: 0 }); + }); + }); +});