Free Support Forum - aspose.com

How can I insert page break into predetermined position in word

I had a Repeating Section contains (Name - Plain Text, Year - Plain Text, Description - Rich Text)

If the children of Repeating Section is spanned in two pages, I will add a PageBreak because I don’t want it to be spitted but it seems didn’t work at all.
if (layoutCollector.GetNumPagesSpanned(projectChild) > 0)
{

//1st - it throws “Cannot insert a node of this type at this location”
projectChild.AppendChild(pageBreakRun);
foreach (Paragraph t in projectChild.GetChildNodes(NodeType.Paragraph, true))
{
//2nd approach - didn’t work
t.AppendChild(pageBreakRun);

//3rd approach - didn’t work
var currentNode = builder.CurrentNode;
builder.MoveTo(t);
builder.InsertBreak(BreakType.PageBreak);
builder.MoveTo(currentNode);
}
}

Could you guys please help me out of this situation?

Hi Vova,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.


  • Please attach your input Word document.
  • Please

    create a standalone/runnable simple application (for example a Console
    Application Project
    ) that demonstrates the code (Aspose.Words code) you used to generate
    your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.