//// 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 PAGEREF field options to add// and customize a reference to a page in the current document// containing a specified bookmark.publicclassPageRefFieldOpts {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); // The name of the target bookmark:conststringbmkName = "myBookmark"; // The PageRefFieldOptions class provides a convenient strong-typed access// to options specific to the 'PAGEREF' MS Word field:var pgRefOpt = newPageRefFieldOptions(doc, bmkName); pgRefOpt.NumberStyle = NumberStyle.UpperRoman; pgRefOpt.Hyperlink = true; // Add a paragraph with the PAGEREF to the document:var p = doc.Body.AddParagraph("Go to page ", doc.Styles[BuiltInStyleId.IndexHeading]).AddComplexField(pgRefOpt); p.GetRange().Runs.Add("..."); // Add some pages:var rnd = Util.NewRandom();for (int i = 0; i < rnd.Next(20, 25); i++) { doc.Body.AddParagraph(Util.LoremIpsumPar()); }// End with the bookmarked paragraph: doc.Body.AddParagraph("The end.").GetRange().Bookmarks.Add(bmkName); // For reference add a simple page header with page number to the document:var phdr = doc.Body.Sections.First.Headers[HeaderFooterType.Primary].Body.AddParagraph(doc.Styles[BuiltInStyleId.Closing]); phdr.AddComplexField(newPageFieldOptions(doc) { NumberFormat = "'Page '0" }); // Update fields using a specific culture: doc.UpdateFields(newGrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") }); // Done:return doc; } }}