Free Support Forum - aspose.com

How Insert page break?

Hi ,


I am using aspose.words evaluation version 13.1 for .NET

I am inserting by using builder.inserthtml("")

if my HTML is like

1

2

3


if I want to insert pagebrak between tables 1 2 3 so that each table should be on new page

how to inset page break ?

please help me …

Regards ,
Jeevan Joshi.

Hi Jeevan,


Thanks for your inquiry. Please use the following code snippet to achieve your requirements. Hope this helps you. Please let us know if you have any more queries.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document(MyDir

  • "in.doc);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))

{

//Create new paragraph and insert it after table

Paragraph par = new Paragraph(doc);

table.ParentNode.InsertAfter(par, table);

//move documentBuilder cursor to the paragraph

builder.MoveTo(par);

//Insert page break

builder.InsertBreak(BreakType.PageBreak);

}

doc.Save(MyDir + "out.docx");

Hi Tahir ,



It seems ok ,

but most of the time html will not contain only tables and their are many nested tables in Main table, and their are N number of Main tables . so how to insert page break after Main table ?

builder.inserthtml("


");

in this case how to insert pagebreak after tableMain1, tableMain2, tableMain3


Regards ,
Jeevan Joshi.

Hi Jeevan,


Thanks for your inquiry. In this case, please use the Node.GetAncestor method to check either table has any outer table or not. The method gets the first ancestor of the specified NodeType.

Please use the following code snippet to achieve your requirements.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document(MyDir

  • “table.html”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))

{

Node parentNode = table.GetAncestor(NodeType.Table);

if (parentNode == null)

{

//Create new paragraph and insert it after table

Paragraph par = new Paragraph(doc);

table.ParentNode.InsertAfter(par, table);

//move documentBuilder cursor to the paragraph

builder.MoveTo(par);

//Insert page break

builder.InsertBreak(BreakType.PageBreak);

}

}

doc.Save(MyDir + "out.docx");