2

I have a text block in a <div> or <p> which I want not to have a page break within. If the text block does not fit on the current page then I want it on a new page. How can I setup XMLWorker to prevent page breaks within certain tags?

aggsol
  • 2,343
  • 1
  • 32
  • 49
  • You could use XML Worker to create an `ElementList` and then add each element one by one. By using `ColumnText` in simulation mode, you can check whether or not an element fits the page. If it fits the page, add it for real. If it doesn't fit, create a `newPage()` before adding it for real. – Bruno Lowagie Apr 13 '15 at 10:14
  • @BrunoLowagie But then the information of unbreakable text blocks wouldn't be in the HTML, would it? Might a custom tag be a valid approach? – aggsol Apr 13 '15 at 11:26
  • Does such a tag or CSS property exist in HTML or CSS? Also: you have access to the `TagFactory`, you could implement that behavior for self-defined tags. – Bruno Lowagie Apr 13 '15 at 11:32
  • @BrunoLowagie Yes there is `page-break-inside: avoid;` but the page-break samples of iText do not discuss it. I will give it a try later. – aggsol Apr 13 '15 at 13:01
  • @BrunoLowagie I tried a custom CSS for `CSSResolver` and inline style. Both ways the `XMLWorker` does *not* recognize `page-break-inside: avoid;` to prevent page breaks within text blocks. – aggsol Apr 15 '15 at 07:57
  • 1
    Maybe it's not documented because it's not supported. XML Worker is developed based on feedback of customers. We use customer tickets to decide which features need to be developed in the subsequent sprints. Maybe none of our customers needed `page-break-inside: avoid;` which would explain why it's not supported. – Bruno Lowagie Apr 15 '15 at 08:01

1 Answers1

4

As of version 5.5.7 the XMLWorker in iText supports page-break-inside: avoid; See Changelog

Update 2023-01-17: iText 5 is now legacy software and has been superseeded by iText 7. I don't know if version 7 works like 4. An archoved version of the changelog has been archived.

aggsol
  • 2,343
  • 1
  • 32
  • 49