Skip to content

Commit

Permalink
Fix page cascade options when text overflows (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
hollandjake authored Feb 5, 2025
1 parent 868e9be commit ee7208b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
16 changes: 16 additions & 0 deletions tests/unit/page.spec.js
Original file line number Diff line number Diff line change
@@ -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 });
});
});
});

0 comments on commit ee7208b

Please sign in to comment.