Skip to content

Conversation

Ranger1230
Copy link

I added the ability to provide the class html2pdf__page-break-avoid on an element that you would like to try and avoid breaking in the middle of if possible. This is useful for images so you don't have half the image on one page and half the image on the next. This will insert a div with a height computed (just like the logic for html2pdf__page-break) that will cause a page break to be put in before the element.

This will only help to avoid page breaks, if an element with this class is larger than 1 page it will still have a page break in it.

Copy link

@adbahrani adbahrani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source need to change to this.prop.container

Copy link
Owner

@eKoopmans eKoopmans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Ranger1230, thank you very much! It's a simple and useful solution. There are currently 4 pagebreak PRs, I'm looking into combining them into one. Thanks again!

}, this);

// Enable avoiding page-breaks in the middle of elements.
var pageBreakAvoids = source.querySelectorAll('.html2pdf__page-break-avoid');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @adbahrani pointed out, source should be this.prop.container.

@Greensahil
Copy link

How did you achieve this? Can I implement this solution to paragraphs and input fields instead of images?

@eKoopmans
Copy link
Owner

Hi, closing as these features were combined into #153. Thanks again for the contribution, I'll add you as a contributor on the readme!

P.S. @Greensahil, check the readme for the page-break feature added in v0.9.1. It can avoid page-breaks on whatever you want, including "everything" ({mode: 'avoid-all'}) or individual types of elements ({avoid: ['p', 'input']}).

@eKoopmans eKoopmans closed this Jan 17, 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