Hi Tony,
Thanks
for sharing the detail. In your input document, the page breaks are in Run nodes as [Page break]April 2, 2015. So the text ‘April 2, 2015’ is at page 2 and page break is at page 1. Due to this issue, you are not getting the correct output. You can workaround this issue by using following code example.
Hope this helps you. Please let us know if you have any more queries.
Document doc = new Document(MyDir + "TestPages.doc");
LayoutCollector collector = new LayoutCollector(doc);
// Retrieve all paragraphs in the document.
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
// Iterate through all paragraphs
foreach (Paragraph para in paragraphs)
{
foreach (Run run in para.Runs)
{
Console.WriteLine(run.Text);
if (run.Text.StartsWith(ControlChar.PageBreak))
{
if (run.ParentParagraph.PreviousSibling != null)
{
((Paragraph)run.ParentParagraph.PreviousSibling).AppendChild(new Run(doc, ControlChar.PageBreak));
}
run.Text = run.Text.Replace(ControlChar.PageBreak, "");
}
}
}
doc.Save(MyDir + "Out.doc");
DocumentPageSplitter splitter = new DocumentPageSplitter(collector);
for (int i = 1; i <= doc.PageCount; i++)
{
Aspose.Words.Document dstDoc = splitter.GetDocumentOfPage(i);
dstDoc.Save(MyDir + "Out" + i + ".docx");
}