Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Assigning a unique ID for each annotation in JS

Guest
Apr 07, 2016 Apr 07, 2016

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.

TOPICS
Acrobat SDK and JavaScript , Windows
908
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2016 Apr 07, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2016 Apr 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2016 Apr 07, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2016 Apr 07, 2016
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines