We have a problem finding out the page count after adding content to the end of a word doc using DocumentBuilder.
Step 1, we merge content into the word doc using MailMerge.Execute()
// note the callback includes a DocumentBuilder
HandleMergeField callback = new HandleMergeField();
docTemplate.WordDoc.MailMerge.FieldMergingCallback = callback;
docTemplate.WordDoc.MailMerge.Execute(fieldNames, fieldValues.ToArray());
Step 2, we determine the page count from docTemplate.WordDoc.PageCount. This PageCount is correct at this time.
Step 3, we append a horizontal line to the end of the document, using the Builder instance that was part of the callback from earlier
// Add end line
builder.MoveToDocumentEnd();
builder.Writeln();
Shape endOfContentLine = new Shape(docTemplate.WordDoc, ShapeType.Line);
endOfContentLine.Name = END_OF_WORD_CONTENT;
endOfContentLine.Bounds = new RectangleF(0, 0, 500, 0);
endOfContentLine.StrokeColor = Color.Red;
builder.InsertNode(endOfContentLine);
builder.Writeln();
Step 4, we check the PageCount again from docTemplate.WordDoc.PageCount. This PageCount is WRONG in cases where the shape added above causes a new page.
Step 5, we append several page breaks to the end of the docuemnt, using the same builder
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.PageBreak);
OUR PROBLEM is in Step 4 - the Page Count after appending content (the shape) the WordDoc.PageCount is WRONG if the new content spilled over to a new page. We have tried adding more content (like a small paragraph of HTML) and we have the same problem. the WordDoc.PageCount is wrong.
QUESTION - How do we get an ACCURATE PAGE COUNT after appending content?
See attached.Artifact GHLCITD.zip (15.8 KB)