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

Free Support Forum - aspose.com

Pdf file creation with page break


I am creating a pdf file from html using code snippet :

pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString + “” + txtExportMain.Text + "

" + txtExportLegend.Text + “”);


What I need to do is check if enough space is available in the page for “txtExportLegend.Text”, If there is not enough space available on the page to fit the entire content then I would want to push the content to start on the next page. Is there a feature in the product that I can leverage to achieve this .

Thanks ,


Hi Dhanesh,

Thanks for using our products.

You may check the following documentation link for details and code snippets as per your requirement.

How to – Convert HTML to PDF using InLineHTML approach

Moreover, you can use IsKeptTogether property to indicates that all lines in the paragraph remains in the same page.

Please do let us know if you need any further assistance.

Thanks & Regards,

not sure on how can i use IsKeptTogether
property with a html table ?

Hi Dhanesh,

Thanks for your interest in our products.

Kindly find the below code in which IsKeptTogether property is used for your reference.


// Instantiate an object PDF class
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

// Read the contents of HTML file into StreamReader object
StreamReader r = File.OpenText(@"D:/pdftest/HTML2pdf.html");

//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());

// enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = true;

//enable the property to display paragraph text on the same page
text2.IsKeptTogether = true;

//Add the text paragraphs containing HTML text to the section

// Specify the URL which serves as images database
pdf.HtmlInfo.ImgUrl = "D:/pdftest/MemoryStream/";

//Save the pdf document

Please do let us know if you need any further assistance.

Thanks & Regards,