Change page orientation PDF

Manipulate PDF
11/2/2011

Downloads

[Visual Studio 2010 Sample Project.zip]: /support/articles/144/Visual Studio 2010 Sample Project.zip "Visual Studio 2010 Sample Project.zip" [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))
    {
        document.Write(outFile);
    }
}
        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
            Next

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

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