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

Free Support Forum - aspose.com

Page Break is not inserted before tables

Hi,

We are running the following code to insert a page break in the beginning of the document :

var cdoc = new Document(@“C:\example.docm”);
var cdocBuilder = new DocumentBuilder(cdoc);
cdocBuilder.MoveToDocumentStart();
cdocBuilder.InsertBreak(BreakType.PageBreak);
cdocBuilder.Document.Save(@“C:\exampleResult.docm”);

The code is working correctly except when example.docm starts with a table (see the attached file). In this case, no page break is inserted. We discovered the bug in Aspose.Words 13.4.0.0 and We could reproduce it in the latest release.

Can you provide us with a fix or a workaround?

Thank you,

Jawad

Hi Jawad,


Thanks for your inquiry. If the first node of the document is table, you need to insert an empty paragraph before the table and then inset page break as shown in following code snippet. Please use the following code snippet to achieve you requirements. Hope this helps you. Please let us know if you have any more queries.

Document doc = new
Document(MyDir + “example.docm”);<o:p></o:p>

var cdocBuilder = new DocumentBuilder(doc);

if (doc.FirstSection.Body.FirstChild.NodeType == NodeType.Table)

{

Paragraph para = new Paragraph(doc);

Run run = new Run(doc, "");

para.AppendChild(run);

doc.FirstSection.Body.InsertBefore(para, doc.FirstSection.Body.FirstChild);

cdocBuilder.MoveTo(run);

cdocBuilder.InsertBreak(BreakType.PageBreak);

}

else

{

cdocBuilder.MoveToDocumentStart();

cdocBuilder.InsertBreak(BreakType.PageBreak);

}

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