private static void BuildDocument(List<Source> sources, WordprocessingDocument output) { // This list is used to eliminate duplicate images List<ImageData> images = new List<ImageData>(); output.AddMainDocumentPart(); XDocument mainPart = output.MainDocumentPart.GetXDocument(); mainPart.Add(new XElement(ns + "document", ns_attrs, new XElement(ns + "body"))); if (sources.Count > 0) { output.CopyStartingParts(sources[0].Document, images); bool lastKeepSections = false; foreach (Source source in sources) { output.AppendDocument(source.Document, source.Contents, source.KeepSections, lastKeepSections, images); lastKeepSections = source.KeepSections; } } }