//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using GrapeCity.Documents.Word;
using GrapeCity.Documents.Word.Fields;
namespace DsWordWeb.Demos
{
// TBD:
public class PageRefFieldOpts
{
public GcWordDocument CreateDocx()
{
var doc = new GcWordDocument();
// The bookmark name:
const string bmkName = "bmk";
// The PageRefFieldOptions class provides a convenient strong-typed access
// to options specific to the 'PAGEREF' MS Word field.
var pgRefOpt = new PageRefFieldOptions(doc, bmkName);
pgRefOpt.NumberStyle = NumberStyle.UpperRoman;
pgRefOpt.Hyperlink = true;
// Add a page header that includes the page number:
var pgOptHeader = new PageFieldOptions(doc);
pgOptHeader.NumberStyle = NumberStyle.Decimal;
doc.Body.Sections.First.Headers[HeaderFooterType.Primary].Body.AddParagraph("Page header - page ").AddComplexField(pgOptHeader);
// Add a paragraph with the PAGEREF:
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);
// Update fields using a specific culture:
doc.UpdateFields(new GrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") });
// Done:
return doc;
}
}
}