@johnmann04
Please note that DocumentBuilder.MoveToParagraph moves the cursor in scope of current section. So, it is necessary to call DocumentBuilder.MoveToSection method before navigating to paragraph from another section. Please check the following code snippet to resolve this issue.
private static void AddPageBreakAndSectionHeader(Document doc, string headerText)
{
DocumentBuilder builder = new DocumentBuilder(doc);
LayoutCollector collector = new LayoutCollector(doc);
int pageIndex = 1;
for (int index = 0; index < doc.Sections.Count; index++)
{
Section section = doc.Sections[index];
builder.MoveToSection(index); // Move to a specific section.
NodeCollection paragraphs = section.Body.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph paragraph in paragraphs)
{
if (collector.GetEndPageIndex(paragraph) != pageIndex)
continue;
builder.MoveToParagraph(paragraphs.IndexOf(paragraph), 0);
builder.StartBookmark("BM_Page" + pageIndex);
builder.EndBookmark("BM_Page" + pageIndex);
pageIndex++;
}
}
...
}