Pdf to Html- avoiding divs being broken

Hey there,


Currently using Aspose.Pdf and trying to produce PDFs from dynamically-generated HTML. As the html is dynamic, we can’t really decide in advance where we want to put page breaks in.

We’re using BindHtml on the Pdf class.

We’ve tried using both:

page-break-before: always; page-break-inside: avoid;

Inline and via CSS at the top of the file. However, Aspose seems to still just put page breaks right through elements.

I’ve also looked at manipulating the generated Section/table paragraph structure somehow, but the structure doesn’t seem to wrap divs very well - most of the elements are all in one cell’s Paragraphs.

Is there any way we can prevent Aspose page-breaking right through the middle of divs?

Cheers

Hi There,


Thanks for contacting support.

I will appreciate if you please share some of the sample generated HTML string / file along with the sample code you are using to convert it into the PDF file. It will help us to understand your requirement exactly and address it accordingly.

We are sorry for this inconvenience.

Best Regards,

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ‘Helvetica Neue’; -webkit-text-stroke: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ‘Helvetica Neue’; -webkit-text-stroke: #000000; min-height: 14.0px}
span.s1 {font-kerning: none}
Sure,


.pdf-text-input {
height: 40px;
width: 500px;
background-color: #FFF;
}

.rows-1 {
height: 100px;
}

p {
margin-top: 0;
}

.control {
margin-top: 18px;
padding-bottom: 20px;
page-break-before: always;
page-break-inside: avoid;
}

ul {
padding-left: 0;
margin: 0;
padding: 0;
}

body {
font-family: Arial;
}

.main {
background-color: #dcdcdc;
padding: 20px;
font-size: 10pt;
}

td.select-spacer {
padding: 2px 0;
}

h4 {
font-size: 10.5pt;
margin: 10px 0;
}

h2 {
margin-top: 0;
font-size: 17pt;
}

.validation {
padding-left: 15px;
margin-left: 0;
}

My Pdf

Section 1

Textbox

required

Description


Textbox

required

Description


Textbox

required

Description


Textbox

required

Description


Textbox

required

Description


Textbox

required

Description


Textbox

required

Description



Textbox

required

Description


Textbox

required

Description


Textbox

required

Description


Textbox

required

Description


Textbox

required

Description


Textbox

required

Description




protected virtual void ConvertHtmlToPdf(Stream inputStream, Stream outputStream)
{
Pdf pdf = new Pdf();
// Specify the Character encoding for HTML file
pdf.HtmlInfo.CharSet = "UTF-8";
pdf.HtmlInfo.CharsetApplyingLevelOfForce = HtmlInfo.CharsetApplyingForceLevel.UseWhenImpossibleDetectFromContent;

pdf.IsLandscape = false;
pdf.PageSetup.Margin.Top = 10;
pdf.PageSetup.Margin.Bottom = 10;
pdf.PageSetup.Margin.Left = 10;
pdf.PageSetup.Margin.Right = 10;

pdf.BindHTML(inputStream, "");
pdf.Save(outputStream);
}

We're just writing the html file to a stream, and outputting it as a stream which we later write to a pdf file. It creates the PDF fine, but when you try it you can see the output doesn't look good because the div with class 'control' can get split over multiple pages. The page doesn't break well. As I mentioned earlier, the process of generating this html is dynamic so it would be exceptionally difficult to insert page breaks in the correct places even if they worked.

Thanks for your help.

Hi There,


Thanks for sharing further details.

I have tested the scenario and have managed to reproduce the problem that the generated PDF doesn’t break well. For the sake of correction, I have logged a ticket PDFNET-42500 in our issue tracking system. We will further look into the details of the problem and will keep you updated within this forum thread on its resolution. Please be patient and spare us little time. We are sorry for the inconvenience.

Best Regards,

Great,


Thanks for the update Fahad. It would be great to hear about any progress on the issue.

Cheers.

You will be notified as soon as the issue is resolved or we have some definite updates on it.


Best Regards,

Has the support for ‘page-break-inside: avoid’ been added yet? I still do not see it mentioned in any of the release notes.

@Miftaul

Another ticket as PDFNET-51824 has been logged in our issue tracking system dedicated for adding support of mentioned CSS Property. We have linked it with this forum thread so that you would receive a notification as soon as it is added. Please be patient and spare us some time. We are sorry for the inconvenience.