Hello,
I am trying to replace a tag in a word document with a page number using this code.
LayoutCollector layout = new LayoutCollector(doc);
foreach (var node in doc.GetChildNodes(NodeType.Any, true))
{
int pagenum = layout.GetStartPageIndex(node);
if (node.GetText().Contains("PageToBeReplaced"))
{
node.Range.Replace("PageToBeReplaced", pagenum.ToString());
}
}
when saved as a pdf the tags “PageToBeReplaced” are not replaced at all.
If I replace pagenum.ToString() with “random string” but keep everything else the same it is still not replacing the tags, If I comment out the following line it replaces the tags with the random string
int pagenum = layout.GetStartPageIndex(node);
it apears that layout.GetStartPageIndex(node) is making doc lose reference to the node.