Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for flowing text always appending a new page #1256

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Unreleased

- Allow applying 'underline' and 'strike' text styling together on a text
- Text will flow to the following page instead of always appending a new page at the end

### [v0.12.0] - 2021-04-04

Expand Down
27 changes: 21 additions & 6 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,25 @@ class PDFDocument extends stream.Readable {
return this;
}

continueOnNewPage(options) {
const pageMarkings = this.endPageMarkings(this.page);

this.addPage(options);
continueOnNextPage(options) {
let pageIndex;

if (
this._pageBuffer &&
(pageIndex = this._pageBuffer.indexOf(this.page)) !==
this._pageBuffer.length - 1
) {
// The page isn't the last in the buffer, so jump to the next page
this.switchToPage(pageIndex + 1);
// Now position the cursor at the top margin
this.y = this.page.margins.top;
} else {
const pageMarkings = this.endPageMarkings(this.page);
// If the page is the last one in the buffer, add a new page.
this.addPage(options);

this.initPageMarkings(pageMarkings);
this.initPageMarkings(pageMarkings);
}

return this;
}
Expand Down Expand Up @@ -216,7 +229,9 @@ class PDFDocument extends stream.Readable {
addNamedEmbeddedFile(name, ref) {
if (!this._root.data.Names.data.EmbeddedFiles) {
// disabling /Limits for this tree fixes attachments not showing in Adobe Reader
this._root.data.Names.data.EmbeddedFiles = new PDFNameTree({ limits: false });
this._root.data.Names.data.EmbeddedFiles = new PDFNameTree({
limits: false
});
}

// add filespec to EmbeddedFiles
Expand Down
2 changes: 1 addition & 1 deletion lib/line_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class LineWrapper extends EventEmitter {
return false;
}

this.document.continueOnNewPage();
this.document.continueOnNextPage();
this.column = 1;
this.startY = this.document.page.margins.top;
this.maxY = this.document.page.maxY();
Expand Down