Another comment : I noticed that the doc.UpdatePageLayout() method takes many many times, for exemple 3 or 4 s for a big complex document (33 pages). That is a problem for my application because I have to get page number for several nodes. The solution is easy (call doc.UpdatePageLayout(); once only) and here is it :
/// <summary>
/// Get the page number of
nodes
/// </summary>
public static List<int>
GetPageNumberOfNodes(List<Node> nodeList)
{
Document
doc = (Document)nodeList[0].Document;
DocumentBuilder builder = new DocumentBuilder(doc);
List<Field>
fieldList = new List<Field>();
List<int>
indexList = new List<int>();
foreach (Node run in nodeList)
{
if (run.GetAncestor(NodeType.HeaderFooter)
!= null)
throw new
Exception("Can't
find the page number of a node inside a header or footer, it will return the
last page. This is the correct behaviour");
builder.MoveTo(run);
Field field = builder.InsertField(" PAGE ");
fieldList.Add(field);
}
doc.UpdatePageLayout(); // Long operation
foreach(Field
field in fieldList)
{
string number = GetFieldValue(field.Start);
if (number.Equals("XXX"))
throw new
Exception("Can't
find the page number of a node inside a field or bookmark");
int pageNum = int.Parse(number);
field.Remove();
indexList.Add(pageNum);
}
return indexList;
}