コード例 #1
0
ファイル: SectionContent.cs プロジェクト: sidea-sk/DocxToPdf
 public SectionContent(
     IEnumerable <PageContextElement> childs,
     ColumnsConfiguration columnsConfiguration,
     SectionContentBreak sectionBreak)
 {
     _childs = childs.ToArray();
     _columnsConfiguration = columnsConfiguration;
     this.SectionBreak     = sectionBreak;
 }
コード例 #2
0
        private static IEnumerable <SectionContent> SplitToSectionContents(
            this IEnumerable <OpenXml.OpenXmlCompositeElement> xmlElements,
            ColumnsConfiguration columnsConfiguration,
            IImageAccessor imageAccessor,
            IStyleFactory styleFactory)
        {
            var sectionContents = new List <SectionContent>();

            var stack           = xmlElements.ToStack();
            var contentElements = new List <OpenXml.OpenXmlCompositeElement>();

            while (stack.Count > 0)
            {
                var e = stack.Pop();
                switch (e)
                {
                case Word.Paragraph p:
                {
                    var(begin, @break, end) = p.SplitByNextBreak();
                    if (@break == SectionContentBreak.None)
                    {
                        contentElements.Add(p);
                    }
                    else
                    {
                        if (end != null)
                        {
                            stack.Push(end);
                        }

                        contentElements.Add(begin);
                        var childElements = contentElements.CreatePageElements(imageAccessor, styleFactory);
                        sectionContents.Add(new SectionContent(childElements, columnsConfiguration, @break));
                        contentElements.Clear();
                    }
                }
                break;

                default:
                    contentElements.Add(e);
                    break;
                }
            }

            if (contentElements.Count > 0)
            {
                var childElements = contentElements.CreatePageElements(imageAccessor, styleFactory);
                sectionContents.Add(new SectionContent(childElements, columnsConfiguration, SectionContentBreak.None));
            }

            return(sectionContents);
        }