Skip navigation
valeri_dzia
Currently Being Moderated

detect annotation

Jun 18, 2012 7:10 AM

Is it possible to detect new annotation on a PDF and show it?

 

I wrote this code :

 

var k=0;

var n=1;

while(k<n){

    var a = this.getAnnots();

    var str ="My annotations : \n";

    if(a==null)

        app.alert("0");

    else{

          n=a.length;

          app.alert(a[k].contents);

          k++;

        }

     }

 

when I add new annotation it doesn't show them

 
Replies
  • Currently Being Moderated
    Jun 18, 2012 7:32 AM   in reply to valeri_dzia

    You have to resan the PDF for new anotations.

     

    You need to use the doc method syncAnnotScan to detect any added annotations since the PDF was opened.

     

    Look at the example for getAnnots method.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 18, 2012 1:45 PM   in reply to valeri_dzia

    It works for me when there is an annotation.  But it locks up in an infinite loop.

     

    Try:

     

    k=-1;

    p=0;

    while(k<0){

        this.syncAnnotScan();

        annots= this.getAnnots();

        if(annots == null) {

    app.alert("No Annotations Found!");

    k = 0;

    }

        if(p!=annots.length){

            p=annots.length;

            app.alert(p);

      k = 0;

        }

        }

     

    If you want to see if a new annotation has been added while the PDF is open, you need to add a timed event.

     

    Acrobat only processed a single thread  at a time. So once yo start a JavaScript loop nothing else will happen until that script ends.

     

    I see nothing in your script that will ever end your do while loop and you also need to put the sync scan within the loop or the annotations for the doucment will never be updated with the added annotations.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 6:52 AM   in reply to valeri_dzia

    There is only one person in a copy of a PDF at time, and that person should know if they add an annotation.

     

    If you chose to use the event listener you will need to track the count of annotations to determine if a new annotation is added or one is just updated. You will also have to code for the deletion of an annotation.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 12:41 PM   in reply to valeri_dzia

    You need to create a variable and be very careful as to when you update it.

     

    I do not understand what you are trying to accomplish.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 8:10 AM   in reply to valeri_dzia

    It appears in the comments navigation panel and on the PDF.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points