5 Replies Latest reply on Jan 26, 2017 7:39 AM by chrisp19015023

    JavaScript to store the file open count in a text file

    Level 1
      Hi,

      Can we write a javascript in pdf such that when the pdf file is opened, the file open count is stored in a text file locally. Every time, the pdf file is opened, the count should be incremented in the text file. This is basically to check how many time a particular pdf file is opened by an user.

      The text file path should be defined in the javascript.
        • 1. Re: JavaScript to store the file open count in a text file
          George_Johnson MVP & Adobe Community Professional
          It would be easier to use a global variable that you've set to be persistent. See the Acrobat JavaScript reference for more information about the global object. Does it have to be a text file? Does it have to work with Reader?

          George
          • 2. Re: JavaScript to store the file open count in a text file
            Level 1
            Hi George,

            Thank you for your suggestion. But I am a novice in scripting. I do not know scripting and first time looking into scripting in Adobe.

            The answer to your questions

            1. Does it have to be a text file?

            Text file would be easier as the end user would have notepad (text editor) in the system. If any database is required, it would be more complicated. It could be also an excel or word file.

            2. Does it have to work with Reader?

            The script has to be written in a PDF file and when the end user opens the PDF file through Adobe Reader, the count should be incremented and the count be stored in the text file.

            The idea behind this script is to know how many times, the user has opened the PDF file.

            I would be extremely happy if somebody could send me the script for this purpose.

            Regards'

            Shelly D'silva
            • 3. Re: JavaScript to store the file open count in a text file
              George_Johnson MVP & Adobe Community Professional
              Reader is not able to write to a text file, so you will have to use a global persistent variable.

              The script you would use is very simple, and should be set up to run when the document is opened. You can do this by creating a document-level script. The code can look something like:


              // Set up a routine that creates
              // and/or increments a global count
              // variable that keeps track of how
              // many times the document has been
              // opened on this machine

              (function () {

                  // Set up the variable name
                  // This needs to be unique for each document
                  var count_var = "my_doc_open_count";

                  // Create global variable if it doesn't already exist
                  // and make it persistent
                  if (typeof global[count_var] === "undefined") {
                      global[count_var] = 0;
                      global.setPersistent(count_var, true);
                  }

                  // Increment the counter
                  global[count_var] += 1;

                  // Notify user how many times the document has been opened
                  // This is mostly for testing, so comment it out if not needed
                  app.alert("This document has been opened " + global[count_var] + " times.", 3);

              })();


              Read the Acrobat JavaScript reference and the accompanying scripting guide for more information. Note that Reader users may have to enable the use of globally persistent variables for this to work.

              George
              1 person found this helpful
              • 4. Re: JavaScript to store the file open count in a text file
                George_Johnson MVP & Adobe Community Professional
                > Note that Reader users may have to enable the use of globally persistent variables for this to work.

                Ignore that part, I was thinking about something else.
                • 5. Re: JavaScript to store the file open count in a text file
                  chrisp19015023

                  Hello George,

                  i am a novice scripter so thank you for your patience in advance, i was wondering how i could use the script to make to alert the user to check for an updated version of the form?