I have a word document and within it want to put the total pages into a table, sounds simple enough. When I use this line of code it gives me the wrong amount of pages, it should be 7 pages but instead I get 54, no idea where its getting this figure from?
docbuilder.InsertField(“NUMPAGES”, “”)
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField(FieldType.FieldNumPages, true);
doc.Save(MyDir + "Out.docx");
I’m now getting field code 26 is not invalid or not supported, does this mean I need to upgrade? The code i’m using is:
docbuilder.InsertField(Aspose.Words.Fields.FieldType.FieldNumPages, True)
It appears in the object browser so its as if its there, I’m using TFS libraries hence why I’ve included the full path
Thanks for your response, unfortunately an upgrade doesn’t solve this, still get the issue. Its strange as my header will work using this line of code:
docbuilder.InsertField(“NUMPAGES”, “”)
But if I place this in my class somewhere else it produces a very high number!..
If when the document is loaded you right click on the field in question and click the update field it works
Fix
oWord.ActiveDocument.Bookmarks(“bk”).Range.Text = oDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages)
- Please attach your input Word document.
- Please
create a standalone/runnable simple application (for example a Console
Application Project) that demonstrates the code (Aspose.Words code) you used to generate
your output document - Please attach the output Word file that shows the undesired behavior.
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.