I want to change a page orientation of word document using openXML. I am replacing a new paragraph and adding a table. After that i need to chnage the orientation of that page to Landscape
This is the code I am using
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(mem, true, openSettings))
{
HtmlConverter converter = new HtmlConverter(wordDoc.MainDocumentPart);
var newParagraphs = converter.Parse(GetTable1HTML());
var body = wordDoc.MainDocumentPart.Document.Body;
//styling
var para1 = new Wordprocessing.Paragraph(new Wordprocessing.Run(newParagraphs)) { RsidParagraphAddition = "00BA2F0F", RsidParagraphProperties = "00BA2F0F", RsidRunAdditionDefault = "00BA2F0F" };
Wordprocessing.ParagraphProperties paragraphProperties1 = new Wordprocessing.ParagraphProperties();
Wordprocessing.SectionProperties sectionProp1 = new Wordprocessing.SectionProperties(new Wordprocessing.PageSize()
{ Width = (UInt32Value)35840U, Height = (UInt32Value)22240U, Orient = Wordprocessing.PageOrientationValues.Landscape })
{ RsidR = "00BA2F0F" };
paragraphProperties1.Append(sectionProp1);
//Table1
var paragraphsTable1 = body.Descendants<Wordprocessing.Paragraph>().
Where(e1 => e1.InnerText.Contains("<text to search>")).FirstOrDefault();
if (paragraphsTable1 == null)
{
return null;
}
//para1.Append(paragraphProperties1);
paragraphsTable1.InsertBeforeSelf<Wordprocessing.Paragraph>(para1).Append(paragraphProperties1);
paragraphsTable1.Remove();}