Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I've seen problems with arrays before, but it does look as if you are creating a 2 dimensional array.
Copy link to clipboard
Copied
My understanding is that a two dimensional array is needed for the purpose: first dimension for the x coordinates and the second one for the y ones.
Anyway I also tried using a one dimensional array applying the following changes to the procedure
[...]
Dim PolVertices(7) As Variant ' only four vertices are needed
[...]
PolVertices(0) = 0
PolVertices(1) = 10
PolVertices(2) = 0
PolVertices(3) = 0
PolVertices(4) = 20
PolVertices(5) = 10
PolVertices(6) = 20
PolVertices(7) = 0
[...]
But the same error a the same point is given back.
Thanks anyway,
Michele.
Copy link to clipboard
Copied
2D arrays are hardly used in PDF so that looks more plausible. But maybe there is just no way to pass arrays. (Or maybe an array of variants isn't of itself a variant...)
Some have resorted to AFExecuteThisJavaScript.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now