I'm trying to read the annotations of a pdf file
Dim AcrApp As Acrobat.Acroapp
Dim AcrAvDoc As Acrobat.AcroAVDoc
Dim pdDoc As Acrobat.CAcroPDDoc
Dim Jso As Object
Dim Annots() As Variant
Dim Annot As Object
Dim Props As Object
Dim strContent, strSubType, strAuthor, strSubject As String
Set AcrApp = New Acrobat.Acroapp
Set AcrAvDoc = AcrApp.GetActiveDoc
Set pdDoc = AcrAvDoc.GetPDDoc
Set Jso = pdDoc.GetJSObject
Set Annots() = Jso.getannots ‘ HERE I GET THE ERROR "impossible to assign to the matrix" and the procedure blocks
For Each Annot In Annots
Set Props = Annot.getprops
strAuthor = Props.Author
strSubject = Props.Subject
strContent = Props.contents
strSubType = Props.Type
Call WriteTable(strAuthor, strSubject, strContent, strSubType) ' this is an external routine
Set Props = Nothing
Set Annot = Nothing
Set Annots = Nothing
Set Jso = Nothing
Set pdDoc = Nothing
Set AcrAvDoc = Nothing
Set AcrApp = Nothing
There is anything wrong in the declaration of Annots on the usage of the getannots method ?
I solved the problem... by chance only.
In place of the above
Set Annots() = Jso.getannots
I used the following instruction
Annots = Jso.getannots()
and it works.
I tried also
Set Annots = Jso.getannots, but I got the same error as above...
I did not understand fully the reason anyway...
This is a VBA related question and has nothing to do with the Acrobat API: The "set" operator assigns a reference to an object to a variable. In your case, you don't have an object variable - you declared the variable as an array of objects (or actually variants, but the underlying problem is the same).
I am no VB or VBA expert, but there are a few things you need to know when programming in VBA. Try to find a good tutorial.
I am having similar issues too.
I am trying to export annotations from a pdf to excel using a macro.
The code is working except for the fact that if I try to assign parameters to GetAnnots() I receive an error message saying "Named argument not found".
If I don't assign any parameter to GetAnnots the code works but the comments are not in order by page.
''Access JSO object
Dim JSO As Object
Set JSO = AcroPDDoc.GetJSObject
''get total number of annotations
''get list of annotations in document
Dim Annotations() As Object
Annotations = JSO.GetAnnots(nSortBy:=ANSB_Page, bReverse:=True)
Do you have any suggestion?
First, there are many problems with the conversion between VB and JS, especially when it comes to objects and function arguments.
Thanks a lot for your explanation. I will look into folder level functions. It is more complicated than what I expected!
I wish I could just get a list of menu items related to OCR.
I read throught the whole annotation, referring you code. It is working. Thanks.