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

Text flowing over multiple pages in parallel columns skips a page #1201

Closed
rexxmagnus opened this issue Dec 22, 2020 · 2 comments
Closed

Text flowing over multiple pages in parallel columns skips a page #1201

rexxmagnus opened this issue Dec 22, 2020 · 2 comments

Comments

@rexxmagnus
Copy link

rexxmagnus commented Dec 22, 2020

Bug Report

Description of the problem

When I add text in a column that flows over to the next page, then start a new column on the first page, the second column will not flow onto the second page but instead flows onto a new, third, page.

Code sample

`// create a document and pipe to a blob
var doc = new PDFDocument({ size: 'A4', layout: 'landscape', bufferPages: true, margin:28 });
var stream = doc.pipe(blobStream());

doc.text(lorem, 20, 200, {width:200});
doc.switchToPage(0);
doc.text(lorem, 300, 150, {width:200});

// end and display the document in the iframe to the right
doc.end();
stream.on('finish', function() {
iframe.src = stream.toBlobURL('application/pdf');
});`

Your environment

  • pdfkit version: 0.11.0
  • Node version: NA
  • Browser version (if applicable): Firefox 84
  • Operating System: Windows 10

image

@rexxmagnus
Copy link
Author

rexxmagnus commented Dec 22, 2020

I have a suggested fix that may work, but I haven't had time to study the codebase fully.
It seems that flowing onto the next page indiscriminately adds a new page, and I suggest to fix it by checking whether the current page is the last in the document and if so, adding a page. If it's not the last page in the document, jump to the next page.

in line_wrapper.js, the function
nextSection(options)

instead of this.document.addPage() immediately after the check to see whether text height is set, something like the following:

      // 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
            this.document.y = this.document.page.margins.top;
        }
      } else{
            // No pagebuffer?
          this.document.addPage();
      }

@ZobairQ
Copy link

ZobairQ commented Dec 24, 2020

Can you please check and accept the pull-request if that fixes the problem. I am having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants