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
Adobe Expert
April 7, 2016

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

April 7, 2016

Thanks try67 for the reply. Name property is unique but it's a long identifier. I'm looking for an integer. Is it possible to create an unique integer that corresponds to the name property of each annotation?

try67
Adobe Expert
April 7, 2016

You can write a simple function that converts the letters to numbers, by replacing "a" with "1", b with "2", etc.