This example shows how to create a PDF document rotated by 90 degrees for a landscape rather than portrait view.

 

   

Setup
 

We start by creating a PDF document. We use two transforms to apply a generic 90 degree rotation around the center of the document and rotate the drawing rectangle by the same amount. After applying our rotation we add some text to the page.

[C#]
Doc theDoc = new Doc();
// apply a rotation transform
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, b);
theDoc.Transform.Translate(w, 0);

// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;

// add some text
theDoc.Rect.Inset(50, 50);
theDoc.FontSize = 96;
theDoc.AddText("Landscape Orientation");

[Visual Basic]
Dim theDoc As Doc = New Doc()
' apply a rotation transform
Dim w As Double = theDoc.MediaBox.Width
Dim h As Double = theDoc.MediaBox.Height
Dim l As Double = theDoc.MediaBox.Left
Dim b As Double = theDoc.MediaBox.Bottom
theDoc.Transform.Rotate(90, l, b)
theDoc.Transform.Translate(w, 0)

' rotate our rectangle
theDoc.Rect.Width = h
theDoc.Rect.Height = w

' add some text
theDoc.Rect.Inset(50, 50)
theDoc.FontSize = 96
theDoc.AddText("Landscape Orientation")

 

   

Rotate
 

Drawing the text rotated does not rotate the page itself. To change the default orientation of the document we need to apply a rotation to the root page object. By doing this we ensure that every page in the document is viewed rotated.

[C#]
// adjust the default rotation and save
int theID = theDoc.GetInfoInt(theDoc.Root, "Pages");
theDoc.SetInfo(theID, "/Rotate", "90");
theDoc.Save(Server.MapPath("landscape.pdf"));
theDoc.Clear();

[Visual Basic]
' adjust the default rotation and save
Dim theID As Integer = theDoc.GetInfoInt(theDoc.Root,"Pages")
theDoc.SetInfo(theID, "/Rotate", "90")
theDoc.Save(Server.MapPath("landscape.pdf"))
theDoc.Clear()

 

   

Results
 


landscape.pdf