There seems to be a bug in the LayoutCollector. It thinks that the first run on page #2 is part of page #1. Here is some code to reproduce (set a break point on: “*** This should be the start of page two” ).
Aspose.Words v13.5.0.0
Microsoft Word 2013
.NET 4.5
Thanks!
var doc = new Document("Hamlet.docx");
var collector = new LayoutCollector(doc);
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
bool nextRunIsPageTwo = false;
foreach (Paragraph curParagraph in paragraphs)
{
Console.WriteLine("*** New Paragraph");
foreach (Run curRun in curParagraph.Runs)
{
if (nextRunIsPageTwo)
{
Console.WriteLine("*** This should be the start of page two");
nextRunIsPageTwo = false;
}
Console.WriteLine("{0}-{1}: {2}",
collector.GetStartPageIndex(curRun),
collector.GetEndPageIndex(curRun),
curRun.Text);
if (curRun.Text.Contains("Exit"))
nextRunIsPageTwo = true;
}