Change page orientation PDF

Manipulate PDF


[Visual Studio 2010 Sample]: /support/articles/144/Visual Studio 2010 Sample "Visual Studio 2010 Sample" [change-orientation-pdf.png]: /support/articles/144/change-orientation-pdf.png "change-orientation-pdf.png" The orientation property of a page is a viewer instruction. It is independent of the content. By setting page.Orientation to 90, we tell the viewer that this page should be displayed 90-degrees rotated.

Code sample to change the page orientation PDF

using (FileStream inFile = new FileStream(@"..\..\../inputDocuments/PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
    // open the document
    Document document = new Document(inFile);

    // enumerate the pages 
    foreach (Page page in document.Pages)
        // change the orientation of the page
        page.Orientation = Orientation.Rotate90;

    // write the target document to disk
    using (FileStream outFile = new FileStream(@"..\../output.pdf", FileMode.Create, FileAccess.Write))
        Using inFile As New FileStream("..\..\../inputDocuments/PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)
            ' open the document
            Dim document As New Document(inFile)

            ' enumerate the pages 
            For Each page As Page In document.Pages
                ' change the orientation of the page
                page.Orientation = Orientation.Rotate90

            ' write the target document to disk
            Using outFile As New FileStream("..\../output.pdf", FileMode.Create, FileAccess.Write)
            End Using
        End Using

And then the resulting PDF will be rotated like so: ![change-orientation-pdf.png]