private static HeaderFooterConfiguration GetHeaderFooterConfiguration( this Word.SectionProperties wordSectionProperties, Pack.MainDocumentPart mainDocument, HeaderFooterConfiguration previousHeaderFooterConfiguration) { var hasTitlePage = wordSectionProperties.ChildsOfType <Word.TitlePage>().SingleOrDefault() .IsOn(ifOnOffTypeNull: false, ifOnOffValueNull: true); var headerRefs = wordSectionProperties .ChildsOfType <Word.HeaderReference>() .Select(fr => new HeaderFooterRef(fr.Id, fr.Type)); var footerRefs = wordSectionProperties .ChildsOfType <Word.FooterReference>() .Select(fr => new HeaderFooterRef(fr.Id, fr.Type)); return(previousHeaderFooterConfiguration.Inherited(mainDocument, hasTitlePage, headerRefs, footerRefs)); }
private static PageMargin GetPageMargin(this Word.SectionProperties sectionProperties) { var pageMargin = sectionProperties.ChildsOfType <Word.PageMargin>().Single(); return(new PageMargin( pageMargin.Top.DxaToPoint(), pageMargin.Right.DxaToPoint(), pageMargin.Bottom.DxaToPoint(), pageMargin.Left.DxaToPoint(), pageMargin.Header.DxaToPoint(), pageMargin.Footer.DxaToPoint())); }
private static PageConfiguration GetPageConfiguration( this Word.SectionProperties sectionProperties) { var pageSize = sectionProperties.ChildsOfType <Word.PageSize>().Single(); var w = pageSize.Width.DxaToPoint(); var h = pageSize.Height.DxaToPoint(); var orientation = (pageSize.Orient?.Value ?? Word.PageOrientationValues.Portrait) == Word.PageOrientationValues.Portrait ? PageOrientation.Portrait : PageOrientation.Landscape; return(new PageConfiguration(new Size(w, h), orientation)); }
private static IEnumerable <ColumnConfig> GetSectionColumnConfigs( this Word.SectionProperties wordSectionProperties, PageConfiguration page, PageMargin pageMargin) { var columns = wordSectionProperties .ChildsOfType <Word.Columns>() .SingleOrDefault(); var totalColumnsWidth = page.Width - pageMargin.HorizontalMargins; var columnsCount = columns.ColumnCount?.Value ?? 1; if (columnsCount == 1) { return(new[] { new ColumnConfig(totalColumnsWidth, 0) }); } if (columns.EqualWidth.IsOn(true)) { var space = columns.Space.ToPoint(); var columnWidth = (totalColumnsWidth - space * (columnsCount - 1)) / columnsCount; return(Enumerable.Range(0, columnsCount) .Select(i => { var s = i == columnsCount - 1 ? 0 : space; return new ColumnConfig(columnWidth, s); }) .ToArray()); } var cols = columns .ChildsOfType <Word.Column>() .Select(col => { var cw = col.Width.ToPoint(); var space = col.Space.ToPoint(); return(new ColumnConfig(cw, space)); }); return(cols); }
private static SectionProperties CreateSectionProperties( this Word.SectionProperties wordSectionProperties, Pack.MainDocumentPart mainDocument, bool isFirstSection, HeaderFooterConfiguration inheritHeaderFooterConfiguration) { var pageCongifuration = wordSectionProperties.GetPageConfiguration(); var pageMargin = wordSectionProperties.GetPageMargin(); var sectionMark = wordSectionProperties.ChildsOfType <Word.SectionType>().SingleOrDefault()?.Val ?? Word.SectionMarkValues.NextPage; var requiresNewPage = isFirstSection || sectionMark == Word.SectionMarkValues.NextPage; var headerFooterConfiguration = wordSectionProperties .GetHeaderFooterConfiguration(mainDocument, inheritHeaderFooterConfiguration); return(new SectionProperties( pageCongifuration, headerFooterConfiguration, pageMargin, requiresNewPage)); }
public static Word.SectionMarkValues GetSectionMark(this Word.SectionProperties sectionProperties) { var st = sectionProperties.ChildsOfType <Word.SectionType>().SingleOrDefault(); return(st?.Val ?? Word.SectionMarkValues.NextPage); }