This project has moved. For the latest updates, please go here.

landscape/portrait options for page/paragraphs

Feb 11, 2013 at 5:30 AM
Can anyone tell me how to set paragraph or page orientation after page break?

Thanks in advance.

I am trying to do landscape/portrait options for page/paragraphs using page layout class.



Regards
Shailesh Naik
Feb 13, 2013 at 3:58 PM
hmm am not sure what you mean by setting landscape options for a paragraph, but for a document I tend to use this.
DocX document = DocX.Create(@"d:\LineChart.docx")
document.PageLayout.Orientation = Novacode.Orientation.Landscape;
document.Save();
Feb 14, 2013 at 4:55 AM
Thanks Prerak for your reply.


I need code where we can set orientation for each page in document likewise we can do in Word Document.


Regards
Shailesh
Aug 1, 2013 at 2:59 PM
Hi,

I'm trying to create a Word document with Landscape Orientation in my project using DocX 1.0.0.12. As Prerak suggested above I have tried code line "document.PageLayout.Orientation", but getting an error saying "Novacode.DocX does not contain a definition for pageLayout......."

Can anyone help me on this?

Regards,
Mithun.
Developer
Aug 1, 2013 at 3:01 PM
Compile the source and try that. The binary hasn't been updated in a while.
Aug 1, 2013 at 3:23 PM
Hi,

Thank for the suggestion, By mistakenly I was Loading DocX 1.0.0.7.
Now Its Working Properly.
Thank you Very Much.

Regards
Mithun.
Mar 4, 2015 at 4:40 PM
Edited Mar 5, 2015 at 5:05 AM
Hi,
I also would like to have such a feature, so I played a little. The following does not work as expected -- Word has a really strange behavior here:
        public void SectionBreak()
        {
            Console.WriteLine("\tSectionBreak()");

            // Create a new document.
            using (DocX document = DocX.Create(@"SectionBreak.docx"))
            {
                document.PageLayout.Orientation = Novacode.Orientation.Landscape;

                // Insert a Paragraph into this document.
                Paragraph p = document.InsertParagraph();


                // Append some text and add formatting.
                p.Append("landscape");

                document.InsertSectionPageBreak(false);
                p = document.InsertParagraph("portrait");

                document.InsertSectionPageBreak(false);
                p = document.InsertParagraph("portrait");

                document.InsertSectionPageBreak(false);
                p = document.InsertParagraph("landscape");

                // Save this document to disk.
                document.Save();
                Console.WriteLine("\tCreated: docs\\SectionBreak.docx\n");
            }
        }
With the above code I got four pages (as expected) with the following orientations:
  1. landscape (expected)
  2. portrait (not expected)
  3. portrait (not expected)
  4. landscape (expected)
Trying to change the orientation using
                document.PageLayout.Orientation = Novacode.Orientation.Portrait/Landscape;
does not help.

The DocX generated XML looks like this:
    <w:body>
        <w:sectPr w:rsidR="003E25F4" w:rsidSect="00FC3028">
            <w:pgSz w:w="16838" w:h="11906" w:orient="landscape" />
            <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"
                w:header="708" w:footer="708" w:gutter="0" />
            <w:cols w:space="708" />
            <w:docGrid w:linePitch="360" />
        </w:sectPr>
        <w:p>
            <w:pPr />
            <w:r>
                <w:t>landscape</w:t>
            </w:r>
        </w:p>
        <w:p>
            <w:pPr>
                <w:sectPr />
            </w:pPr>
        </w:p>
        <w:p>
            <w:pPr />
            <w:r>
                <w:rPr>
                    <w:lang w:val="en-EN" />
                </w:rPr>
                <w:t>portrait</w:t>
            </w:r>
        </w:p>
        <w:p>
            <w:pPr>
                <w:sectPr />
            </w:pPr>
        </w:p>
        <w:p>
            <w:pPr />
            <w:r>
                <w:rPr>
                    <w:lang w:val="en-EN" />
                </w:rPr>
                <w:t>portrait</w:t>
            </w:r>
        </w:p>
        <w:p>
            <w:pPr>
                <w:sectPr />
            </w:pPr>
        </w:p>
        <w:p>
            <w:pPr />
            <w:r>
                <w:rPr>
                    <w:lang w:val="en-EN" />
                </w:rPr>
                <w:t>landscape</w:t>
            </w:r>
        </w:p>
    </w:body>
Anyone additional hints?