// 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 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"));
            // DsWord 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 DsWord 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;