views:

1050

answers:

1

What I need to do is query an iTextSharp AcroField to check if it is rotated, and if so capture the value of the rotation.

So If I have the following field:

Dim af As iTextSharp.text.pdf.AcroFields = stamper.AcroFields
Dim afi As iTextSharp.text.pdf.AcroFields.Item 

afi = af.GetFieldItem("fieldName")

What do I need to do to get the rotation (in degrees) of that specific field?

A: 

Once you have the AcroField.Item as shown above, you can get field rotation in degrees like so:

Dim widgetDict As PdfDictionary = Nothing
Dim mkDict As PdfDictionary = Nothing
Dim rNum As PdfNumber = Nothing

widgetDict = afi.widgets(0)
If Not widgetDict Is Nothing Then
    mkDict = widgetDict.GetAsDict(PdfName.MK)
    If Not mkDict Is Nothing Then
     rNum = mkDict.GetAsNumber(PdfName.R)
     If Not rNum Is Nothing Then
         Return rNum.DoubleValue     
     End If
    End If
End If
Return 0

Keep in mind this is the rotation of the AcroField only. You will also have to check to see if:

  • The page itself is also rotated (PDFReader.GetPageRotation(pageNo) )
  • The field rotation is relative to the page (iTextSharp.text.pdf.PdfFormField.FLAGS_NOROTATE)
Corey Downie