This project has moved and is read-only. For the latest updates, please go here.

Change Orientation to landscape

Feb 21, 2013 at 11:42 PM
Is there a way to change page orientation to landscape
Coordinator
Feb 25, 2013 at 8:43 AM
Feb 25, 2013 at 10:55 PM

Thanks onizet.

This is what I have done.

static SectionProperties ChangeOrientationToLandscape()

{

SectionProperties sectionProperties = new SectionProperties();

PageSize pageSize = new PageSize()

{

Width = (UInt32Value)15840U,

Height = (UInt32Value)12240U,

Orient = PageOrientationValues.Landscape

};

PageMargin pageMargin = new PageMargin()

{

Top = 1440,

Right = (UInt32Value)1440U,

Bottom = 1440,

Left = (UInt32Value)1440U,

Header = (UInt32Value)720U,

Footer = (UInt32Value)720U,

Gutter = (UInt32Value)0U

};

Columns columns = new Columns() { Space = "720" };

DocGrid docGrid = new DocGrid() { LinePitch = 360 };

sectionProperties.Append(pageSize, pageMargin, columns, docGrid);

return sectionProperties;

}

static SectionProperties ChangeOrientationToPortrait()

{

SectionProperties sectionProperties = new SectionProperties();

PageSize pageSize = new PageSize()

{

Width = (UInt32Value)12240U,

Height = (UInt32Value)15840U,

Orient = PageOrientationValues.Portrait

};

PageMargin pageMargin = new PageMargin()

{

Top = 1440,

Right = (UInt32Value)1440U,

Bottom = 1440,

Left = (UInt32Value)1440U,

Header = (UInt32Value)720U,

Footer = (UInt32Value)720U,

Gutter = (UInt32Value)0U

};

Columns columns = new Columns() { Space = "720" };

DocGrid docGrid = new DocGrid() { LinePitch = 360 };

sectionProperties.Append(pageSize, pageMargin, columns, docGrid);

return sectionProperties;

}

And called like this in my main file

body.Append(new Paragraph(new ParagraphProperties(new SectionProperties(ChangeOrientationToLandscape()))));

Coordinator
Mar 5, 2013 at 9:42 PM
I've been interested in ways to add section breaks to Export to Word, both to do Landscape Orientation and also to reset page numbering. Thank you for posting this.

So far, however, I haven't gotten the above code to work for me. What I have been asked to do is switch to landscape orientation based off of a <div> class attribute, similar to how page breaks are done. For instance, HtmlToOpenXml supports the following for page breaks:
<div style="page-break-after:always">&nbsp;</div>
I've been asked to support something similar for landscape, like:
<div class="SectionBreakLandscape">&nbsp;</div>
I tried to take the above code and apply it to HtmlConverter.ProcessContainerAttributes, where page breaks are set:
                string classValue = en.Attributes["class"];
                if (classValue == "SectionBreakLandscape")
                {
                    paragraphs.Add(new Paragraph(new ParagraphProperties(new SectionProperties(ChangeOrientationToLandscape()))));
                    newParagraph = true;
                }
However, no section break occurs and the page does not switch to landscape. What am I missing to make this work?
Coordinator
Mar 6, 2013 at 1:06 PM
ddeforge> after all your commitment to this project, do you want to join me as a developer ? You can PM me to discuss offline about this
Mar 22, 2013 at 6:00 AM

Thanks for the offer. Sorry I was away for some time and would be starting on my project using your library in a week’s time and would love to contribute.

From: onizet [email removed]
Sent: Thursday, 7 March 2013 12:07 AM
To: Bajwa, Navpreet Singh
Subject: Re: Change Orientation to landscape [html2openxml:434042]

From: onizet

ddeforge> after all your commitment to this project, do you want to join me as a developer ? You can PM me to discuss offline about this

Feb 11, 2014 at 8:46 PM
Hello,
First off, thanks for this wonderful library. It has helped me a bunch. I was curious if anything like the above has been implemented yet. I have a requirement that certain pages with large images need to be landscape oriented, while other pages with text need to be portrait. Does there yet exist a way to switch pages to different orientations (not the entire document). Many thanks!
Coordinator
Feb 24, 2014 at 8:36 AM
Hello,


Sorry for late reply. Yes something has been implemented. You can declare your body as follow:
<body style="page-orientation: landscape"></body>
to turn your page in landscape. Unlickily, currently it's available only on <body> and not yet on <div>.