Page Rotation Property. The number of degrees to rotate the page before display. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

 

Type Default Read Only Description
[C#] int

[Visual Basic]
Integer
 n/a  No The number of degrees to rotate the page before display.

 

   

Notes
 

The number of degrees clockwise to rotate the page before display.

The values 0 and 180 indicate portrait orientation. The values 90 and 270 indicate landscape orientation.

This value should be a multiple of 90.

 

   

Example
 

This example shows how to use the Rotation property to determine how to add a PDF page - which may be rotated - to a portrait PDF page.

[C#]
using(Doc doc = new Doc(), src = new Doc()) {
  src.Read("landscape.pdf");
  int rotation = ((Page)src.ObjectSoup[src.Page]).Rotation;
  bool landscape = src.MediaBox.Width > src.MediaBox.Height;
  doc.Page = doc.AddPage();  // output is always in portrait
  if(landscape){
    switch(rotation) {
    default:
    case 90:
      doc.Transform.Rotate(270, 0, 0);
      doc.Transform.Translate(0, doc.MediaBox.Height);
      break;
    case 180:
    case 270:
      doc.Transform.Rotate(90, 0, 0);
      doc.Transform.Translate(doc.MediaBox.Width, 0);
      break;
    }
    doc.Rect.SetRect(0, 0, doc.MediaBox.Height, doc.MediaBox.Width);
  } else {
    switch(rotation) {
    case 90:
    case 180:
      doc.Transform.Rotate(180, 0, 0);
      doc.Transform.Translate(doc.MediaBox.Width, doc.MediaBox.Height);
      break;
    }
  }
  doc.AddImageDoc(src, 1, null);
  doc.Save("addtoportrait.pdf");
}

[Visual Basic]
Sub ...
  Using doc As New Doc(), src As New Doc()
    src.Read("landscape.pdf")
    Dim rotation As Integer = ((Page)src.ObjectSoup(src.Page)).Rotation
    ' output is always in portrait
    If landscape Then
      Select Case rotate
        Case Else, 90
          doc.Transform.Rotate(270, 0, 0)
          doc.Transform.Translate(0, doc.MediaBox.Height)
          Exit Select
        Case 180, 270
          doc.Transform.Rotate(90, 0, 0)
          doc.Transform.Translate(doc.MediaBox.Width, 0)
          Exit Select
      End Select
      doc.Rect.SetRect(0, 0, doc.MediaBox.Height, doc.MediaBox.Width)
    Else
      Select Case rotate
        Case 90, 180
          doc.Transform.Rotate(180, 0, 0)
          doc.Transform.Translate(doc.MediaBox.Width, doc.MediaBox.Height)
          Exit Select
      End Select
    End If
    doc.AddImageDoc(src, 1, Nothing)
    doc.Save("addtoportrait.pdf")
  End Using
End Sub


landscape.pdf


addtoportrait.pdf