RemovePageBreaks.cs
//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System.IO;
using System.Linq;
using GrapeCity.Documents.Word;

namespace DsWordWeb.Demos
{
    // This sample shows how to remove all hard page breaks
    // (including page breaks associated with sections)
    // from a DOCX.
    // See also the RemoveEmptyPages sample.
    public class RemovePageBreaks
    {
        public GcWordDocument CreateDocx()
        {
            var doc = new GcWordDocument();
            doc.Load(Path.Combine("Resources", "WordDocs", "breaks.docx"));
            // Remove all hard page breaks:
            foreach (var brr in doc.Body.Texts.Where(txt => txt is Break br && br.Type == BreakType.Page).ToArray())
                brr.Delete();
            // Change all section starts to continuous:
            for (var sec = doc.Body.Sections.First; sec.Next != null; sec = sec.Next)
                if (sec.PageSetup.SectionStart != SectionStart.Continuous)
                    sec.PageSetup.SectionStart = SectionStart.Continuous;
            return doc;
        }
    }
}