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

Free Support Forum - aspose.com

Support for page-break-inside: avoid;

Hi Aspose,

At the moment we do our line breaks with ‘page-break-before: always;’ Unfortunatly we do not always know how long the content is. We would like to avoid a page break within a certain div with the css prop: break-inside: avoid; It is in the css standard ( https://developer.mozilla.org/en-US/docs/Web/CSS/break-inside ) but asopose does not react to this css prop.

var pdfDocument = new Document();

HtmlLoadOptions options = new HtmlLoadOptions();
var html = "<div style=\"border: 10px solid red; break-inside: avoid; height: 200px\">dont break me </div><div style=\"border: 10px solid red; break-inside: avoid; height: 200px\">dont break me </div><div style=\"border: 10px solid red; break-inside: avoid; height: 200px\">dont break me </div><div style=\"border: 10px solid red; break-inside: avoid; height: 200px\">dont break me </div><div style=\"border: 10px solid red; break-inside: avoid; height: 200px\">dont break me </div>";
            HtmlFragment textFragment = new HtmlFragment(html)
            {
                HtmlLoadOptions = options
            };

var page = pdfDocument.Pages.Add();
page.Paragraphs.Add(textFragment);
pdfDocument.Save("html_test.PDF");

Example while it breaks:

Full source code: https://github.com/JoostVanVelthoven/AsposeAvoidElementBreak

Is their any workaround possible?

@JoostDelft

At the moment, the API only offers a property i.e. HtmlLoadOptions.IsRenderToSinglePage in order to generate single page PDF. We have logged an enhancement ticket as PDFNET-51824 in our issue tracking system for the support of CSS property that you mentioned. We will further look into the details of the ticket and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.