Sections.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 GrapeCity.Documents.Word;

namespace DsWordWeb.Demos
{
    // Shows how to add sections to a document
    // and modify the page setup of sections.
    public class Sections
    {
        public GcWordDocument CreateDocx()
        {
            GcWordDocument doc = new GcWordDocument();

            var sec1 = doc.Body.Sections.First;
            // Change default margins from 1" to 1/2":
            sec1.PageSetup.Margin.Left = sec1.PageSetup.Margin.Right =
                sec1.PageSetup.Margin.Top = sec1.PageSetup.Margin.Bottom = 36;
            var pars1 = sec1.GetRange().Paragraphs;
            pars1.Add("Section 1, Paragraph 1. " + Util.LoremIpsumPar());
            pars1.Add("Section 1, Paragraph 2. " + Util.LoremIpsumPar());
            pars1.Add("Section 1, Paragraph 3. " + Util.LoremIpsumPar());

            var sec2 = doc.Body.Paragraphs.Last.AddSectionBreak();
            // For the 2nd section, change page orientation:
            sec2.PageSetup.Size.Orientation = PageOrientation.Landscape;
            var pars2 = sec2.GetRange().Paragraphs;
            pars2.Add("Section 2, Paragraph 1. " + Util.LoremIpsumPar());
            pars2.Add("Section 2, Paragraph 2. " + Util.LoremIpsumPar());
            pars2.Add("Section 2, Paragraph 3. " + Util.LoremIpsumPar());

            // Done:
            return doc;
        }
    }
}