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

Syntax for forcing a page break #700

Open
marioperna opened this issue Feb 27, 2023 · 2 comments
Open

Syntax for forcing a page break #700

marioperna opened this issue Feb 27, 2023 · 2 comments

Comments

@marioperna
Copy link

Hello,

I am generating a pdf starting from an HTML template containing a table.

Currently, my issue is about how to interrupt the table row before the end of the page or In general how to interrupt the page and go to the next.

I've already tried to use some CSS selectors such as page-break-before, page-break-after Etc... but none of them seem to work well.
Is there any special syntax for this package to force the breaking?

I know this package is deprecated, but I hope you can help me out.
Thanks a lot

@drickchote
Copy link

I got a great result by placing a margin-bottom of 2000px, as the margin does not pass to the next page, it worked for me.

@drickchote
Copy link

I noticed that the margin was going to the pages towards the end of the file. To resolve this, I calculated the number of pixels each page occupies. Based on the number of elements on my table.

This is my code

let html = generatehtml()

 const MAX_ITEMS_ON_PAGE = 18
 const inicialMarginHeight = items.length <= MAX_ITEMS_ON_PAGE ? 430 : 800

 let tableHeaderHeight = items.length > 0 ? 60 : 0
 let itemsHeight = (items.length % MAX_ITEMS_ON_PAGE + 1) * 20 
 let tableMargin = inicialMarginHeight - tableHeaderHeight - itemsHeight

html += `<div style='margin-bottom:${tableMargin}px; background-color: red'/>`

The red background helped me to know the right fit

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