/// <summary>
        /// Concatenates all documents into a single one
        /// </summary>
        /// <param name="documents">Documents to concatenate</param>
        /// <param name="outputFilePath">Path of file with concatenate contents</param>
        public static PTWordprocessingDocument JoinDocuments(IEnumerable <OpenXmlDocument> documents, string outputFilePath)
        {
            // Creates a new, empty document
            PTWordprocessingDocument newDocument = new PTWordprocessingDocument(outputFilePath, true);
            Collection <XElement>    contents    = new Collection <XElement>();

            // Extracts from each document, the body element inside the main document part
            foreach (PTWordprocessingDocument doc in documents)
            {
                XDocument mainDocumentPartXml = doc.GetXDocument(doc.Document.MainDocumentPart);

                XElement bodyElement = mainDocumentPartXml.Descendants(ns + "body").First();

                foreach (XElement content in bodyElement.Elements())
                {
                    contents.Add(content);
                }
            }

            // Adds into the new document all the extracted content from source files
            newDocument.InnerContent.SetContent(contents);
            return(newDocument);
        }
        /// <summary>
        /// Splits a multisection wordprocessing document into several documents containing one section each
        /// </summary>
        /// <param name="outputPath">Path to store document fragments after splitting</param>
        /// <param name="prefix">Prefix to use when constructing resultant file name</param>
        public override Collection <OpenXmlDocument> Split(string outputPath, string prefix)
        {
            Collection <OpenXmlDocument> newList          = new Collection <OpenXmlDocument>();
            MainDocumentPart             mainDocumentPart = parentDocument.Document.MainDocumentPart;
            XDocument mainDocumentPartXml = parentDocument.GetXDocument(mainDocumentPart);

            // Stores elements between section breaks and saves them into a file
            Collection <XElement>    contents    = new Collection <XElement>();
            PTWordprocessingDocument newDocument = null;
            int      fileNameCounter             = 0;
            XElement mainDocumentPartBodyXml     = mainDocumentPartXml.Descendants(ns + "body").First();

            foreach (XElement xmlElement in mainDocumentPartBodyXml.Elements())
            {
                if (xmlElement.Descendants(ns + "sectPr").Count() > 0 ||
                    xmlElement.Name == ns + "sectPr")
                {
                    contents.Add(xmlElement);
                    newDocument = new PTWordprocessingDocument
                                  (
                        string.Format("{0}/{1}_{2}.docx", outputPath, prefix, fileNameCounter),
                        true
                                  );
                    fileNameCounter++;
                    newDocument.InnerContent.SetContent(contents);
                    newDocument.FlushParts();
                    newList.Add(newDocument);
                    contents.Clear();
                }
                else
                {
                    contents.Add(xmlElement);
                }
            }
            return(newList);
        }
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public WordprocessingDocumentManager(PTWordprocessingDocument document)
     : base((OpenXmlDocument)document)
 {
     parentDocument = (PTWordprocessingDocument)base.parentDocument;
 }