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

Free Support Forum - aspose.com

Inserting pagebreak after table

I’m trying to insert a pagebreak after a table (using a new paragraph as the anchor point or location of the pagebreak), but cannot get it to work. This is what I’ve tried so far:

NodeCollection OutTables = DestDoc.GetChildNodes(NodeType.Table, true);
// get the destination table, AFTER which the paragraph will be inserted
Table DestTable = (Table) OutTables[DestTableIndex];
// insert a paragraph after the current destination table
Paragraph par = new Paragraph(DestDoc);
Node node = DestTable.ParentNode.InsertAfter(par, DestTable);
Section currentSect = (Section) par.GetAncestor(NodeType.Section);
// Get index of paragraph in the current section
int parIndex = currentSect.Body.Paragraphs.IndexOf(par);
int sectIndex = DestDoc.Sections.IndexOf(currentSect);
DestBuilder.MoveToParagraph(parIndex, -1);

It seems that the paragraph is inserted in the middle of the table instead of after the table, and the pagebreak is not visible. Any ideas will be highly appreciated.
Best regards and thanks,

Thanks for your inquiry. Please try using the following code:

// Open document and create DocumentBuilder
Document doc = new Document(@"Test117\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get Table
Table tab = doc.FirstSection.Body.Tables[0];
// Create new paragraph and insert it after table
Paragraph par = new Paragraph(doc);
tab.ParentNode.InsertAfter(par, tab);
// move documentBuilder cursor to the paragraph
// Insert page break
// Save output document

I hope this helps.
Best regards.