GlossaryDoc.cs
//
// 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.Xml;
using GrapeCity.Documents.Word;

namespace DsWordWeb.Demos
{
    // This sample demonstrates how to add building blocks to a document's glossary.
    public class GlossaryDoc
    {
        public GcWordDocument CreateDocx()
        {
            var doc = new GcWordDocument();

            doc.Body.Paragraphs.Add("This sample demonstrates adding building blocks (custom headers and footers in this case) " +
                "to the document's glossary. They do not show in the generated document. To use the building blocks, " +
                "open the document in MS Word and explore the document's glossary.");

            // Add header and footer building blocks to the document's glossary:
            AddHeaderBuildingBlockToGlossary(doc);
            AddFooterBuildingBlockToGlossary(doc);

            // Now the document has two building blocks in the glossary.
            // Note that when the document is loaded into MS Word, they will not be visible.
            // To use them, open the document in MS Word and explore the document glossary.
            return doc;
        }

        // Add header building block:
        private void AddHeaderBuildingBlockToGlossary(GcWordDocument doc)
        {
            GlossaryDocument glossary = doc.GlossaryDocument;
            BuildingBlockCollection buildingBlocks = glossary.BuildingBlocks;
            BuildingBlock buildingBlock = buildingBlocks.Add("New cool header", "2019 collection", BuildingBlockGallery.CustomHeaders);
            var bbBody = buildingBlock.Body;
            //here we can modify body as we want
            var p = bbBody.Paragraphs.Add("New cool building block neader");
            p.Style.Font.Color.RGB = Color.Blue;
        }

        // Add footer building block:
        private void AddFooterBuildingBlockToGlossary(GcWordDocument doc)
        {
            GlossaryDocument glossary = doc.GlossaryDocument;
            BuildingBlockCollection buildingBlocks = glossary.BuildingBlocks;
            BuildingBlock buildingBlock = buildingBlocks.Add("New cool footer", "2019 collection", BuildingBlockGallery.CustomFooter);
            var bbBody = buildingBlock.Body;
            // Here we can modify the body as we want:
            var p = bbBody.Paragraphs.Add("New cool building block footer");
            p.Style.Font.Color.RGB = Color.Pink;
        }
    }
}