//
// 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;
using GrapeCity.Documents.Word.Layout;
namespace DsWordWeb.Demos
{
// This sample shows how to use the TOA and TA field options
// to add a TOA (Table of Authorities) field to a DOCX Word document.
public class ToaFieldOpts
{
public GcWordDocument CreateDocx()
{
// Some sample citations to insert into our document:
(string, string)[] cits =
{
("Alejado v. City & Cty. of Honolulu", "89 Hawai'i 221, 971 P.2d 310 (App. 1998)"),
("Anderson v. United States", "612 F.2d 1112 (9th Cir.1980)"),
("Asato v. Procurement Policy Bd.", "132 Hawai'i 333, 322 P.3d 228 (2014)"),
("Awakuni v. Awana", "115 Hawai'i 126, 165 P.3d 1027 (2007)"),
("Baker v. Carr", "369 U.S. (1962)")
};
var doc = new GcWordDocument();
// We will reuse the same instance of TaFieldOptions,
// updating only the citation text, for all TOA entries:
var ta = new TaFieldOptions(doc)
{
Category = 1,
};
// Fill the document with some random text, adding
// a "citation" to the end of each paragraph:
var rand = Util.NewRandom();
for (int i = 0; i < rand.Next(10, 20); ++i)
{
var p = doc.Body.AddParagraph(Util.LoremIpsumPar());
var cit = cits[rand.Next(0, cits.Length - 1)];
p.AddRun("See case " + cit.Item1 + ".");
ta.LongCitation.Text = cit.Item1 + ",\n" + cit.Item2;
p.AddComplexField(ta);
}
// Create and specify options for the table of authorities:
var toa = new ToaFieldOptions(doc)
{
EntriesCategory = 1,
};
// Add a caption for the table of authorities:
doc.Body.AddParagraph("TABLE OF AUTHORITIES");
// Add a paragraph to hold the TOA field:
var field = doc.Body.AddParagraph().AddComplexField(toa);
// Update the TOA field using a specific culture:
field.Update(new WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") });
// Done:
return doc;
}
}
}