//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.Globalization;usingGrapeCity.Documents.Word;usingGrapeCity.Documents.Word.Fields; namespaceDsWordWeb.Demos{// This sample shows how to use the PAGE and NUMPAGES field options// to insert the current and total page numbers into the document// and customize the fields' appearance.publicclassPageFieldOpts {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); // The PageFieldOptions and NumPagesFieldOptions classes provide// convenient strong-typed access to options specific to the// 'PAGE' and 'NUMPAGES' MS Word fields respectively. // PAGE field options for the page header:var pgOptHeader = newPageFieldOptions(doc); pgOptHeader.NumberStyle = NumberStyle.Decimal; // PAGE field options for page numbers in the body:var pgOptBody = newPageFieldOptions(doc); pgOptBody.NumberStyle = NumberStyle.UpperRoman; // NUMPAGES field options:var numpagesOpt = newNumPagesFieldOptions(doc); numpagesOpt.NumberStyle = NumberStyle.Decimal; // Add a page header that includes the current and total page numbers:var para = doc.Body.Sections.First.Headers[HeaderFooterType.Primary].Body.AddParagraph("Page header - page "); para.AddComplexField(pgOptHeader); para.AddRun(" of "); para.AddComplexField(numpagesOpt); // Pick a style that will be used for page numbers in the document body:var pageStyle = doc.Styles[BuiltInStyleId.IndexHeading]; // Add some pages, with periodic inclusions of the PAGE field:var rnd = Util.NewRandom();for (int i = 0; i < rnd.Next(6, 12); i++) {var p = doc.Body.AddParagraph("This text is on page ", pageStyle); p.AddComplexField(pgOptBody); p.AddRun(" of "); p.AddComplexField(numpagesOpt); p.GetRange().Runs.Add(".");var par = Util.LoremIpsumPar(); doc.Body.AddParagraph(par); } // Update fields using a specific culture: doc.UpdateFields(newGrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") }); // Done:return doc; } }}