Copy link to clipboard
Copied
Hi,
I'm trying to read the annotations of a pdf file
Sub ReadAnnotationsTest()
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
Jso.syncAnnotScan
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
Next
Set Props = Nothing
Set Annot = Nothing
Set Annots = Nothing
Set Jso = Nothing
Set pdDoc = Nothing
Set AcrAvDoc = Nothing
Set AcrApp = Nothing
End Sub
There is anything wrong in the declaration of Annots on the usage of the getannots method ?
Thanks,
Michele.
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi Michele,
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.
This is the code i wrote for the javascript object:
''Access JSO object
Dim JSO As Object
Set JSO = AcroPDDoc.GetJSObject
JSO.console.Show ''show javascript console
''get total number of annotations
JSO.syncAnnotScan
''get list of annotations in document
Dim Annotations() As Object
Annotations = JSO.GetAnnots(nSortBy:=ANSB_Page, bReverse:=True)
Do you have any suggestion?
Copy link to clipboard
Copied
First, there are many problems with the conversion between VB and JS, especially when it comes to objects and function arguments.
So the last line of your code won't work because there is no good translation for passing the parameterized arguments. They need to be encapsulated in and object. Remember, your not calling a VB function, your calling a JavaScript function, so there has to be a direct translation between the VB code and the JS code on the other side.
The best technique (and the only that will work well in your case) is to put all your JavaScript into a folder level function, and then call that function from VB. Then you don't have any of these issues.
Copy link to clipboard
Copied
Thanks a lot for your explanation. I will look into folder level functions. It is more complicated than what I expected!
Copy link to clipboard
Copied
I wish I could just get a list of menu items related to OCR.
Copy link to clipboard
Copied
Bob_realvilla wrote
I wish I could just get a list of menu items related to OCR.
Even if you could, you couldn't do anything once you had them. The ability to execute menu items via JavaScript is very restrictive. See link below.
Copy link to clipboard
Copied
I read throught the whole annotation, referring you code. It is working. Thanks.