We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Page/Numpages field and printing


We are experiencing a strange problem when using Apose.Words to print a document where we inserted a page or numpages field.

In the following snippet we create a document and add some text and fields to it before sending it to the printer.

static void Main(string[] args)


var doc = new Aspose.Words.Document();

DocumentBuilder db = new DocumentBuilder(doc);

db.Write(“Page “);


db.Write(” of “);


db.Write(” in this document”);


When we run this program we’d expect a printed document containing the text: “Page 1 of 1 in this document”.
The content instead is only “Page 1” and it will cut off all contant that is inserted after the call to InsertField.

We have tested this in Aspose.Words versions 11.4 ; 11.11 and 13.1. All of them give the same result.

Could this be a bug in Asponse.Words and could you suggest another way of achieving the desired result?


Hi Jan-Peter,

Thanks for your inquiry. Please use the overloaded DocumentBuilder.InsertField method (String, String) to inserts a Word field into a document without updating the field result for Page and NUMPAGES as shown in following code snippet.

The reason why the second overload with the two parameters works is because that particular overload inserts the field without updating it. That is, the result is inserted with what ever you pass instead of the value being calculated. The first overload with only parameter will update the field when it is inserted.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Aspose.Words.Document();<o:p></o:p>

DocumentBuilder db = new DocumentBuilder(doc);

db.Write("Page ");

db.InsertField("PAGE", "");

db.Write(" of ");

db.InsertField("NUMPAGES", "");

db.Write(" in this document");