HTML to PDF with page-break-inside: avoid and background page

1 Answer 5 Views
PdfProcessing WordsProcessing
Kees
Top achievements
Rank 2
Iron
Iron
Kees asked on 09 Oct 2025, 11:12 AM

Hello,

I'm trying to rewrite a PDF-generator function that creates a PDF from HTML (which is the result of an XSLT+xml transform) using another HTML to PDF library to a new function that uses the Telerik methods. That works Ok, but there are 2 things I can't figure out how to do (if even possible) :

- The HTML content consists of a table with uneven row heights, depending on the content. Some rows contain images, some don't. So, I can't determine beforehand which row needs to start on a new page. Currently, I use page-break-inside: avoid on the rows, and that works with the other library, but not with the Telerik methods. Some rows are split over two pages. How can I prevent an element from breaking up over two pages?

- With the current library, I'm able to provide a separate PDF file that is used as a background for every rendered page. That PDF is a single-page PDF with the 'corporate stationery' (don't know how that's called ;-), so the resulting PDF contains multiple pages with the HTML output in the company style. Is something like that possible with the Telerik methods?  I know how to draw a small HTML snippet on a single PDF page, but I can't figure out how to convert HTML to PDF with this background on every page.

Any help is appreciated.

Regards,
Kees

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 13 Oct 2025, 12:58 PM

Hello Kees,

Thank you for reaching out. I am attaching for your disposal a sample project that serves as a solution to your questions and implements the following functionality:

Splitting Rows

Usually, our WordsProcessing library exposes a CanSplit property that can specify whether or not a row can be split across multiple pages:

var tables = flowDocument.EnumerateChildrenOfType<Table>();

foreach (Table table in tables)
{
    foreach (TableRow row in table.Rows)
    {
        row.CanSplit = false;
    }
}

However, this feature is not yet supported for PDF export, which is why we already have a related feature request logged in our Feedback Portal - WordsProcessing: Respect TableRow.CanSplit property when exporting to PDF. If you are interested in this task, please know that you can cast your vote for it in order to increase its priority in our backlog and to subscribe so you can track its progress and receive notifications about potential status updates in the future.

If it fits your requirements, a possible workaround is to manually recreate the PDF table from scratch by copying the HTML table content. You can then call the table.Measure() method after adding each row to check whether it exceeds the page boundaries. If it does, create a new page and continue building the table there.

PDF background

The simplest approach is to export the background PDF file to an image. Then add this image to each page of the main document. The image must be first in the page.Content collection, in order to appear under the rest of the elements. 

For .NET Framework environments, one of the PDF to image export methods can be achieved through our Telerik UI for WinForms - How to Export Each Page as an Image in PDF Documents. Based on your active DevCraft Complete license, you should have access to the Telerik UI for WinForms product. 

Feel free to test and examine the attached project for yourself.

I hope this helps.

Regards,
Yoan
Progress Telerik

Your perspective matters! Join other professionals in the State of Designer-Developer Collaboration 2025: Workflows, Trends and AI survey to share how AI and new workflows are impacting collaboration, and be among the first to see the key findings.
Start the 2025 Survey
Tags
PdfProcessing WordsProcessing
Asked by
Kees
Top achievements
Rank 2
Iron
Iron
Answers by
Yoan
Telerik team
Share this question
or