Free Support Forum - aspose.com

Page number field not showing on next page

Hi,

I was trying to create a document where i inserted Field “PAGE” on each page but it seems that only first field is displaying. All further fields are blank. if you manually update them in word document, they will start to show up, but updating them using document.Update() method doesn’t help.

code I am using:

var doc = new Document();
var docBuilder = new DocumentBuilder(doc);
docBuilder.InsertField(“PAGE”);
docBuilder.InsertBreak(BreakType.PageBreak);
docBuilder.InsertField(“PAGE”);
docBuilder.InsertBreak(BreakType.PageBreak);
docBuilder.InsertField(“PAGE”);
doc.Save(“OutputFiles/Output.docx”);

can you please advice?
thanks
Aga

@acturisaspose,

Thanks for your inquiry. Please call Document.UpdatePageLayout and Document.UpdateFields methods as shown below to get the desired output.

var doc = new Document();
var docBuilder = new DocumentBuilder(doc);
docBuilder.InsertField("PAGE");
docBuilder.InsertBreak(BreakType.PageBreak);
docBuilder.InsertField("PAGE");
docBuilder.InsertBreak(BreakType.PageBreak);
docBuilder.InsertField("PAGE");

doc.UpdatePageLayout();
doc.UpdateFields();
doc.Save(MyDir + @"18.8.docx");