Table row breaks inside across pages when creating PDF from HTML

Hi there,

I have a similar problem to another contributor from a couple of years back (2017) but cannot see how to achieve the solution that your support person describes.

I am referring to this post:

https://forum.aspose.com/t/table-row-content-breaks-between-pages-while-converting-html-to-pdf-net/165755/2

Your response says:

After inserting an HTML content, you can extract table and iterate through the rows.

But the mentioned help topic does not seem to show how to extract a table and iterate the rows after creating that table by loading an HTML fragment. Please could you clarify how to do this.

Furthermore, your example assumes that I will know after how many rows to force a page break. In our case, because the tables are dynamic, this will not be possible and we simply need to prevent any table row from breaking across pages.

In CSS we would want to write something like:

table tr { page-break-inside: avoid !important; }

But this does not seem to have any effect when included within the loaded HTML. The rows still break across pages.

Looking forward to your help.

@JohnOD77

You can try using following CSS property in order to force a page break while converting HTML to PDF:

page-break-before: always;

Furthermore, if this suits you, you can render all your HTML content on a single page by using following flag:

HtmlLoadOptions options = new HtmlLoadOptions();
options.IsRenderToSinglePage = true;
HtmlFragment html = new HtmlFragment("html");
html.HtmlLoadOptions = options;

In case of any issue, please share your sample HTML along with expected output PDF. We will test the scenario in our environment and address it accordingly.