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

Add support for page-breaks to be inserted before elements that would otherwise intersect them #118

Closed
wants to merge 1 commit into from

Conversation

jbryan76
Copy link

@jbryan76 jbryan76 commented May 30, 2018

Any element with class 'html2pdf__avoid-page-break' that intersects a page-break will instead be pushed to the next page by inserting a shim div before it.
Elements with the class that span more than a full page are ignored.
Confirmed working on latest source for documents with multiple pages.

… otherwise intersect them.

Any element with class 'html2pdf__avoid-page-break' that intersects a page-break will instead be pushed to the next page.
@campsoftware
Copy link

This is great! Thank you. It sounds like it'd resolve this issue: https://github.com/ebdrup/html2pdf.it/issues/72

@jbryan76
Copy link
Author

Yes I believe so. Sounds like we could put up for debate best css class name to use to enable it, but we have a project with critical need for this functionality so are using a patched local copy until something official is available.

@campsoftware
Copy link

I see my reply above was from another project. Sorry for the confusion.

@campsoftware
Copy link

Regarding the naming, it might be a good to use 'page-break-before', 'page-break-after' and 'page-break-inside' since those are standards [ https://css-tricks.com/almanac/properties/p/page-break/ ]. Could those be used in addition to 'html2pdf__avoid-page-break' and 'html2pdf__page-break' so older projects don't break?

@jbryan76
Copy link
Author

Those sound better, in particular if they are a standard. They imply some additional patching though since this PR essentially is only for page-break-inside. Another issue is whether to keep the css class approach or try to mine it from the element style itself instead.

Changing html2pdf__avoid-page-break to eg html2pdf__page-break-inside is trivial on my end - it's early enough in the project to have minimal impact. I will probably do that proactively.

If I have time I will update, but ultimately it may be up to eKoopmans who has been silent so far.

@eKoopmans
Copy link
Owner

... Hello! Sorry for the long silence.

Thanks @jbryan76, this is a great addition. And @campsoftware I appreciate the info about the CSS standards, that gives a clear direction on how to go forward. Though I'm not sure how to implement avoid on break-before and break-after...

There are also 4 different pagebreak PRs now, so I'm looking into combining all 4. Do either of you see any issues with adjusting an element's margin (as in #138) instead of injecting resized divs?

I'll probably keep the class-based .html2pdf__page-break in as legacy, for now at least, but focus on using the CSS standards going forward. I'm also planning to add options to avoid breaks on all elements, or on a list of specified elements that can be passed as an html2pdf setting.

@ZabbyCapurin
Copy link

@eKoopmans, do you have a timeline of when you'd have time to combine the PRs and release the page-break changes?

@eKoopmans
Copy link
Owner

@ZabbyCapurin I have a draft mostly finished, I'll submit it as a PR for testing before merging anything in.

@eKoopmans
Copy link
Owner

Hey @ZabbyCapurin @jbryan76 @campsoftware, I've put up a new page-break PR #153, take a look if you have a chance. I haven't had time yet to do any testing with it, so please let me know if there's any issues.

@eKoopmans
Copy link
Owner

Resolved by #153, closing!

@eKoopmans eKoopmans closed this Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants