Change page orientation PDF

Manipulate PDF
11/2/2011

Downloads

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

C# code sample

1 using (FileStream inFile = new FileStream(@"..\..\../inputDocuments/PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)) 2 { 3 // open the document 4 Document document = new Document(inFile); 5 6 // enumerate the pages 7 foreach (Page page in document.Pages) 8 { 9 // change the orientation of the page 10 page.Orientation = Orientation.Rotate90; 11 } 12 13 // write the target document to disk 14 using (FileStream outFile = new FileStream(@"..\../output.pdf", FileMode.Create, FileAccess.Write)) 15 { 16 document.Write(outFile); 17 } 18 }

VB.NET code sample

1 Using inFile As New FileStream("..\..\../inputDocuments/PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read) 2 ' open the document 3 Dim document As New Document(inFile) 4 5 ' enumerate the pages 6 For Each page As Page In document.Pages 7 ' change the orientation of the page 8 page.Orientation = Orientation.Rotate90 9 Next 10 11 ' write the target document to disk 12 Using outFile As New FileStream("..\../output.pdf", FileMode.Create, FileAccess.Write) 13 document.Write(outFile) 14 End Using 15 End Using

And then the resulting PDF will be rotated like so:

change-orientation-pdf.png