Skip navigation
Currently Being Moderated

Creating and tracking counters in Acrobat

Jul 30, 2012 8:15 AM

I need to create a PDF document that is "aware" of how many times it has been opened.  What i want is the capability to send a document for evaluation but place a limit on how many times the document has been viewed, displaying a message to the user when the limit has been reached.  I found this code on another post and I just want to make sure that it will work (obviously the code does not include the message box).

 

Many thanks for your help

 

if (global.count = null)

{

global.count = 0

global.setPersistent("count",true)

}

else

global.count++

 
Replies
  • George Johnson
    9,208 posts
    Aug 11, 2002
    Currently Being Moderated
    Jul 30, 2012 10:03 AM   in reply to steve1dance

    That's not the right way to check for the existence of a global variable. If a global variable does not exist, it will return a value of undefined, not null. Also, the code has a bug such that it actually sets the global to null rather than testing to see if it's equal to null.

     

    Try something like this:

     

    if (typeof global.count === "undefined") {

        global.count = 0;

        global.setPersistent("count", true);

    } else {

        global.count++;

    }

     
    |
    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