using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Xml;
using System.Xml.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using System.Text;
using System.IO.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
/// <summary>
/// DocumentExtensions contains functions to manage the creation, reading and writing of XDocument objects
/// that come from an OpenXmlPackage
/// </summary>
public static class DocumentExtensions
{
public static void RemovePageBreaks(this Document document)
{
List<Break> breaks = document.Descendants<Break>().ToList();
foreach (Break b in breaks)
{
b.Remove();
}
document.Save();
}
public static void RemoveSectionBreaks(this Document document)
{
List<ParagraphProperties> paraProps = document.Descendants<ParagraphProperties>()
.Where(pPr => ParagraphPropertiesExtensions.IsSectionProps(pPr)).ToList();
foreach (ParagraphProperties pPr in paraProps)
{
pPr.RemoveChild<SectionProperties>(pPr.GetFirstChild<SectionProperties>());
}
document.Save();
}