Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Replace integration tests by visual regression tests
- Fix access permissions in PDF version 1.7ext3
- Fix Buffer() is deprecation warning
- Fix page always being added when flowing onto existing page

### [v0.11.0] - 2019-12-03

Expand Down
3 changes: 3 additions & 0 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pages are flushed to the output file yourself rather than letting PDFKit handle
it, just pass `bufferPages: true` as an option to the `PDFDocument` constructor. Then, you can call
`doc.switchToPage(pageNumber)` to switch to a previous page (page numbers start at 0).

When switching back to a previous page, text that flows off the end will run onto the next page
(if it already exists), otherwise a new page will be added at the end of the document.

When you're ready to flush the buffered pages to the output file, call `flushPages`.
This method is automatically called by `doc.end()`, so if you just want to buffer all pages in the document, you
never need to call it. Finally, there is a `bufferedPageRange` method, which returns the range
Expand Down
18 changes: 17 additions & 1 deletion lib/line_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,23 @@ class LineWrapper extends EventEmitter {
return false;
}

this.document.addPage();
// If using a pagebuffer, check whether the page is the last one
if (!!this.document._pageBuffer){
var pageIndex = this.document._pageBuffer.indexOf(this.document.page);
// If the page is the last one in the buffer, add a new page.
if (pageIndex == this.document._pageBuffer.length - 1){
this.document.addPage();
} else {
// The page isn't the last in the buffer, so jump to the next page
this.document.switchToPage(pageIndex + 1);
// Now position the cursor at the top margin
this.document.y = this.document.page.margins.top;
}
} else{
// No pagebuffer?
this.document.addPage();
}

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