How to automate a Polygon Annotation creation?
Hi,
I have question regarding the creation of a new annotation type as "Polygon" through Access VBA.
The "vertices" is defined as an array of array in the Acrobat Javascript API, but it is suggested the refer to the PDF Reference.
In the PDF Reference 1.7 I found nothing more anyway
Vertices - array - (Required) An array of numbers representing the alternating horizontal and vertical coordinates, respectively, of each vertex, in default user space.
So I tried to implement the following procedure:
Sub CreateNewAnnotationPolygon()
Dim AcrApp As Acrobat.Acroapp 'Application Acrobat
Dim AcrAvDoc As Acrobat.AcroAVDoc 'Document actif dans Acrobat
Dim pdDoc As Acrobat.CAcroPDDoc
Dim page As Acrobat.CAcroPDPage
Dim Jso As Object
Dim path As String
Dim popupRect(3) As Integer
Dim Rect(3) As Integer
Dim PolVertices(1, 3) As Variant ' only four vertices are needed
Dim pageRect As Object
Dim Annot As Object
Dim Props As Object
Dim Color(0 To 3) As Variant
Set AcrApp = New Acrobat.Acroapp
Set AcrAvDoc = AcrApp.GetActiveDoc
Set pdDoc = AcrAvDoc.GetPDDoc
Set Jso = pdDoc.GetJSObject
If Not Jso Is Nothing Then
' Get size for page 0 and set up arrays
Set page = pdDoc.AcquirePage(0)
Set pageRect = page.GetSize
Rect(0) = 20 ' to define the position of the annotation
Rect(1) = pageRect.y - 10
Rect(2) = 20 ' actually I doubt if it is correct to define also rect(2) and rect(3)
Rect(3) = pageRect.y
PolVertices(0, 0) = 0
PolVertices(1, 0) = 10
PolVertices(0, 1) = 0
PolVertices(1, 1) = 0
PolVertices(0, 2) = 20
PolVertices(1, 2) = 10
PolVertices(0, 3) = 20
PolVertices(1, 3) = 0
' Create a new Polygon annot
Set Annot = Jso.AddAnnot
Set Props = Annot.getprops
Props.Type = "Polygon"
Props.bordereffectIntensity = 1
Props.Width = 1
Annot.setProps Props
' Fill in a few fields
Set Props = Annot.getprops
Props.page = 0
Props.Rect = Rect
Props.Vertices = PolVertices ' HERE THE PROCEDURE STOPS WITH THE ERROR "Property not supported by the object"
Props.Author = "Michele"
Props.Subject = "Example Polygon shape"
Color(0) = "RGB"
Color(1) = 1#
Color(2) = 0#
Color(3) = 0#
Props.StrokeColor = Color
Annot.setProps Props
pdDoc.Close
'MsgBox "Annotation added"
Else
MsgBox "Failed to open"
End If
Set Annot = Nothing
Set Props = Nothing
Set page = Nothing
Set pageRect = Nothing
Set Jso = Nothing
Set pdDoc = Nothing
Set AcrAvDoc = Nothing
Set AcrApp = Nothing
End Sub
Can you suggest where is the error?
Thanks in advance,
Michele.