Skip to main content
michelem90144782
New Participant
July 13, 2016
Question

How to use the getannots method?

  • July 13, 2016
  • 3 replies
  • 5985 views

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.

This topic has been closed for replies.

3 replies

New Participant
October 22, 2020

I read throught the whole annotation, referring you code. It is working. Thanks.

riccardom15921476
New Participant
March 6, 2019

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?

Thom Parker
Community Expert
March 6, 2019

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.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
riccardom15921476
New Participant
March 7, 2019

Thanks a lot for your explanation. I will look into folder level functions. It is more complicated than what I expected!

michelem90144782
New Participant
July 14, 2016

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...

Karl Heinz  Kremer
Community Expert
July 14, 2016

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.