RemovePageBreaks.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 all hard page breaks
  12. // (including page breaks associated with sections)
  13. // from a DOCX.
  14. // See also the RemoveEmptyPages sample.
  15. public class RemovePageBreaks
  16. {
  17. public GcWordDocument CreateDocx()
  18. {
  19. var doc = new GcWordDocument();
  20. doc.Load(Path.Combine("Resources", "WordDocs", "breaks.docx"));
  21. // Remove all hard page breaks:
  22. foreach (var brr in doc.Body.Texts.Where(txt => txt is Break br && br.Type == BreakType.Page).ToArray())
  23. brr.Delete();
  24. // Change all section starts to continuous:
  25. for (var sec = doc.Body.Sections.First; sec.Next != null; sec = sec.Next)
  26. if (sec.PageSetup.SectionStart != SectionStart.Continuous)
  27. sec.PageSetup.SectionStart = SectionStart.Continuous;
  28. return doc;
  29. }
  30. }
  31. }
  32.