Skip to main content
April 7, 2016
Question

Assigning a unique ID for each annotation in JS

  • April 7, 2016
  • 1 reply
  • 1074 views

Hi everyone,


I made a JS code to export all the annotations in a .pdf file to a .csv file and it works fine. I also need to assign a unique ID number for each row similar to a database table but couldn't figure a way out.


The issue is that if a user deletes an annotation, ID numbers of annotations after the deleted annotation will change if I use value of "i" in the "for" loop. Somehow I need to store the ID numbers in each annotation.


Let's say I have 3 annotations in a .pdf file, and run the code below;


this.syncAnnotScan(); 

var annots = this.getAnnots() 

for ( var i= 0; i< annots.length; i++) { 

    console.println(i+1); 

    console.println("Type:"+annots.type); 

    console.println("Text:"+annots.contents);     

    console.println("-----"); 

}

Results are ;

1

Type:Text

Text:Comment-1

-----

2

Type:Text

Text:Comment-2

-----

3

Type:Text

Text:Comment-3

-----

If I delete the annotation-2, then the results will be;

1

Type:Text

Text:Comment-1

-----

2

Type:Text

Text:Comment-3

-----

I'm trying to keep the ID number "3" for the comment-3 even if I delete the comment-2. Is there a simple way to do that? Any kind of help is appreciated.

Regards.

This topic has been closed for replies.

1 reply

try67
Community Expert
April 7, 2016

Use the name property of each annotation... It's a unique identifier.

Karl Heinz  Kremer
Community Expert
April 7, 2016

Actually, the name may not be unique, but the combination of name and page number will be unique: When you copy and paste an annotation to a different page, the name of the original annotation is used for the copy as well, but when you paste on the same page, the new annotation will have a different name.