Skip to main content
michelem90144782
Participant
Jul 13, 2016 6:01 PM UTC
Question

How to use the getannots method?

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 is closed to new replies. Start a new post to keep the conversation going.

8 replies

Participant
Oct 22, 2020 6:08 PM UTC

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

Translate
riccardom15921476
Participant
Mar 6, 2019 5:48 PM UTC

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?

Translate
Thom Parker
Community Expert
Community Expert
Mar 6, 2019 7:28 PM UTC

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.

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
riccardom15921476
Participant
Mar 7, 2019 7:29 AM UTC

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

Translate
michelem90144782
Participant
Jul 14, 2016 6:50 AM UTC

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

Translate
Karl Heinz  Kremer
Community Expert
Community Expert
Jul 14, 2016 11:06 AM UTC

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.

Translate