RemoveEmptyPages.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System.IO;
  6. using System.Linq;
  7. using GrapeCity.Documents.Word;
  8.  
  9. namespace DsWordWeb.Demos
  10. {
  11. // This sample shows how to remove empty pages that appear
  12. // due to consecutive hard page breaks in a DOCX.
  13. // See also the RemovePageBreaks sample.
  14. public class RemoveEmptyPages
  15. {
  16. public GcWordDocument CreateDocx()
  17. {
  18. var doc = new GcWordDocument();
  19. doc.Load(Path.Combine("Resources", "WordDocs", "empty-pages.docx"));
  20. // DsWord special find chars (see RangeBase.Replace for details):
  21. // &m - page break
  22. // &b - section break
  23. // &p - end of paragraph
  24. doc.Body.Replace("&m&m", "");
  25. // Note that section breaks follow paragraph breaks in DOCX,
  26. // in terms of DsWord Find/Replace this looks as "&p&b":
  27. doc.Body.Replace("&b&p&b", "");
  28. doc.Body.Replace("&m&p&p&b", "&p");
  29. doc.Body.Replace("&b&m", "");
  30. return doc;
  31. }
  32. }
  33. }
  34.