public override VisitorAction VisitSectionEnd(Section section)
{
if (IsCompositeAcrossPage(section))
{
// If a TOC field spans across more than one page then the hyperlink formatting may show through.
// Remove direct formatting to avoid this.
foreach (FieldStart start in section.GetChildNodes(NodeType.FieldStart, true))
{
if (start.FieldType == FieldType.FieldTOC)
{
Field field = start.GetField();
Node node = field.Separator;
while ((node = node.NextPreOrder(section)) != field.End)
if (node.NodeType == NodeType.Run)
((Run)node).Font.ClearFormatting();
}
}
foreach (Section cloneSection in SplitComposite(section))
{
cloneSection.PageSetup.SectionStart = SectionStart.NewPage;
cloneSection.PageSetup.RestartPageNumbering = true;
cloneSection.PageSetup.PageStartingNumber = section.PageSetup.PageStartingNumber + (section.Document.IndexOf(cloneSection) - section.Document.IndexOf(section));
cloneSection.PageSetup.DifferentFirstPageHeaderFooter = false;
RemovePageBreaksFromParagraph(cloneSection.Body.LastParagraph);
}
RemovePageBreaksFromParagraph(section.Body.LastParagraph);
// Add new page numbering for the body of the section as well.
mPageNumberFinder.AddPageNumbersForNode(section.Body, mPageNumberFinder.GetPage(section), mPageNumberFinder.GetPageEnd(section));
}
return VisitorAction.Continue;
}