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

How to add new page automatically once the lines start overflowing the current page? #1451

Open
irshadk-0 opened this issue Jun 14, 2023 · 2 comments

Comments

@irshadk-0
Copy link

The PDFKit docs say that "PDFKit automatically inserts new pages as necessary so you don't have to worry about doing that for long pieces of text", does this also apply in cases where we use doc.moveDown() in such a way that it overflows the current page but will generate a new page automatically?

For example, consider the page height as 595 points.

      doc.y = 552
      doc.moveDown();
      doc.text("1", 300)
      doc.moveDown();
      doc.text("2", 300)
      doc.moveDown();
      doc.text("3", 300)
      doc.moveDown();
      doc.text("4", 300)

This code results in this. As you can see there is only 1 page and the text is overflowing the page.

Screenshot 2023-06-14 at 12 35 44 PM

How can I automatically make PDFKit add a new page once the space on the current page is finished?

Your environment

  • pdfkit version: 0.13.0
  • Node version:
  • Browser version (if applicable):
  • Operating System:
@rohinthr
Copy link

Your code will work. can You share the full code from creating document object to calling end funtion. @irshadk-0

@bugamehmet
Copy link

bugamehmet commented Jul 20, 2023

However, when using doc.moveDown() and scrolling to the bottom of the page, PDFKit will not automatically add a new page if you move beyond the area where the current page should fit. This means that the doc.y coordinate you are using is smaller than the bottom edge of the page.
doc.y = 552;
doc.moveDown();
doc.text("1", 300);
doc.moveDown();
doc.text("2", 300);
doc.moveDown();
doc.text("3", 300);
doc.moveDown();
doc.text("4", 300);

if (doc.y > 595) {
doc.addPage();
}
This way, you will automatically add a new page and prevent texts from spilling out of the page when the doc.y coordinate is greater than the bottom edge of the current page. So your texts will be properly distributed between the pages.

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

3 participants