We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Tables and page breaks


I have a basic HTML document containing a 3 column table. When converting to PDF, we often see that certain rows span 2 pages, depending on the amount of content in a cell.

I have been using the “RowFormat.AllowBreakAcrossPages” option to prevent a given row from extending into a new page. However, I am in a position where I need a bit more. I need to know which CELL of a row is causing the row to extend.

For my document, it is acceptable to allow the BreakAcrossPages if the middle cell content is the cause, but NOT acceptable if the third column is causing the break.

Is there any way I can determine which cell of a row is causing the row to break across the page?

Kind Regards,

Hi Dawn,

Thanks for your inquiry. The RowFormat.AllowBreakAcrossPages is row level property. In your case, you need to calculate the height of second and third cell and set the the value of this property accordingly. We suggest you following solution.

1) Bookmark the contents of second and third cells separately.
2) Calculate the cell height as shown in following code snippet using bookmark.
3) Set the value of RowFormat.AllowBreakAcrossPages to true or false according to your requirements by looking into cell's height.

//e.g conttent of table's first cell are bookmarked with name 'bookmark'

Bookmark bookmark = doc.Range.Bookmarks["bookmark"];

LayoutCollector collector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

var renderObject = collector.GetEntity(bookmark.BookmarkStart);

layoutEnumerator.Current = renderObject;

RectangleF location = layoutEnumerator.Rectangle;

renderObject = collector.GetEntity(bookmark.BookmarkEnd);

layoutEnumerator.Current = renderObject;

RectangleF location2 = layoutEnumerator.Rectangle;

Console.WriteLine(location2.Y - location.Y);