sammyn

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Page break is getting inserted between sources #4366

    sammyn
    Participant

    So, I found the code that is ‘inserting’ the page break, but, I don’t know docx well enough to understand what it is doing. any pointers? this is the code:

            private static void FixUpSectionProperties(WordprocessingDocument newDocument)
            {
                XDocument mainDocumentXDoc = newDocument.MainDocumentPart.GetXDocument();
                mainDocumentXDoc.Declaration.Standalone = "yes";
                mainDocumentXDoc.Declaration.Encoding = "UTF-8";
                XElement body = mainDocumentXDoc.Root.Element(W.body);
                var sectionPropertiesToMove = body
                    .Elements()
                    .Take(body.Elements().Count() - 1)
                    .Where(e => e.Name == W.sectPr)
                    .ToList();
                foreach (var s in sectionPropertiesToMove)
                {
                    var p = s.SiblingsBeforeSelfReverseDocumentOrder().First();
    
                    if (p.Element(W.pPr) == null)
                        p.AddFirst(new XElement(W.pPr));
                    p.Element(W.pPr).Add(s);
                }
                foreach (var s in sectionPropertiesToMove)
                    s.Remove();
            }
    
Viewing 1 post (of 1 total)