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

If it fits, render content on current page, otherwise render on a new page #1159

Open
tomprats opened this issue May 27, 2020 · 1 comment
Open

Comments

@tomprats
Copy link
Contributor

I've been trying to figure out a way to ensure an entire section fits on the remaining part of the page, if not, start a new page with it. Right now the only way I can do it is by calculating the height of a block beforehand, but that gets more and more complicated depending on the content.

Some alternative options I was trying to investigate:

  1. Before each block, save current page state. Run the block, if it overruns the page, reset to the old state and do it on a new page. This would require using the private internals and even then might not work.

  2. Before each block, create a new test document with part of the current state, if the dry run fails then start on a new page, if not, do it on the real PDF. This ended up breaking when using helpers because the test document couldn't have the same context as the actual PDF.

  3. Create the PDF once, when a block overflows the page, re-render the full block on the next page. Actually renders the text every time, but saves the best option. When it finishes going through the whole document, erase it and start over but only using the best options.

I'd appreciate any help. I've been stuck on this a while and haven't made any progress.

@phamdat8
Copy link

phamdat8 commented Aug 2, 2023

In my case, I use prawn-table with just 1 column and each block is one row, row will be rendered in new page if the current page does not enough space.

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

No branches or pull requests

3 participants
@tomprats @phamdat8 and others