diff --git a/OpenXmlFormats/Wordprocessing/Paragraph.cs b/OpenXmlFormats/Wordprocessing/Paragraph.cs index ee98e9284..4369db897 100644 --- a/OpenXmlFormats/Wordprocessing/Paragraph.cs +++ b/OpenXmlFormats/Wordprocessing/Paragraph.cs @@ -1211,11 +1211,24 @@ public CT_NumPr AddNewNumPr() this.numPr = new CT_NumPr(); return this.numPr; } + public CT_SectPr AddNewSectPr() + { + if(this.sectPrField==null) + { + this.sectPrField = new CT_SectPr(); + } + return this.sectPrField; + } public bool IsSetSpacing() { return this.spacing != null; } + + public bool IsSetSectPr() + { + return this.sectPr != null; + } } @@ -3030,6 +3043,18 @@ public bool IsSetTitlePg() return this.titlePgField != null; } + public bool IsSetPgSz() + { + return this.pgSzField != null; + } + + public CT_PageSz AddNewPgSz() + { + if(this.pgSzField == null) + this.pgSzField = new CT_PageSz(); + return this.pgSzField; + } + public CT_OnOff AddNewTitlePg() { if (this.titlePgField == null) diff --git a/ooxml/XWPF/Usermodel/XWPFParagraph.cs b/ooxml/XWPF/Usermodel/XWPFParagraph.cs index c82a58b9c..c3b522752 100644 --- a/ooxml/XWPF/Usermodel/XWPFParagraph.cs +++ b/ooxml/XWPF/Usermodel/XWPFParagraph.cs @@ -1819,6 +1819,34 @@ public XWPFFieldRun CreateFieldRun() return newRun; } + public void ChangeOrientation(ST_PageOrientation orientation) + { + var pPr = paragraph.IsSetPPr() + ? paragraph.pPr + : paragraph.AddNewPPr(); + + // Create inside + var sectPr = pPr.IsSetSectPr() + ? pPr.sectPr + : pPr.AddNewSectPr(); + + var pageSize = sectPr.IsSetPgSz() + ? sectPr.pgSz + : sectPr.AddNewPgSz(); + + pageSize.orient = orientation; + if(orientation== ST_PageOrientation.landscape) + { + pageSize.w = 842 * 20; + pageSize.h = 595 * 20; + } + else + { + pageSize.h = 842 * 20; + pageSize.w = 595 * 20; + } + } + private bool IsTheOnlyCTHyperlinkInRuns(XWPFHyperlinkRun run) { CT_Hyperlink1 ctHyperlink = run.GetCTHyperlink();