All code samples

Change page orientation PDF

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("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("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

Relevant products