// This code is part of GrapeCity Documents for Word samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
using System.IO;
using System.Linq;
using GrapeCity.Documents.Word;

namespace GcWordWeb.Samples
    // This sample shows how to remove empty pages that appear
    // due to consecutive hard page breaks in a DOCX.
    // See also the RemovePageBreaks sample.
    public class RemoveEmptyPages
        public GcWordDocument CreateDocx()
            var doc = new GcWordDocument();
            doc.Load(Path.Combine("Resources", "WordDocs", "empty-pages.docx"));
            // GcWord special find chars (see RangeBase.Replace for details):
            // &m - page break
            // &b - section break
            // &p - end of paragraph
            doc.Body.Replace("&m&m", "");
            // Note that section breaks follow paragraph breaks in DOCX,
            // in terms of GcWord Find/Replace this looks as "&p&b":
            doc.Body.Replace("&b&p&b", "");
            doc.Body.Replace("&m&p&p&b", "&p");
            doc.Body.Replace("&b&m", "");
            return doc;