These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need to create visitor counter inside a pdf

jmartinson
Registered: Feb 15 2011
Posts: 3
Answered

I am new to Acrobat javascript, and need to know how to create a visitor counter inside a PDF. The PDF in question resides on a client website, ie. www.client.com/mypage.pdf. The page that is displayed can only be a PDF, no HTML is allowed, using any HTML on www.client.com is out of the question. Everytime the pdf is opened, I want to increase the counter by one. My best guest is that I need to save the counter variable to a file on the www.client.com domain. The logic goes something like this, in a document level script:
  
. . . // code before . . .
 
if(!pdfOpened) { // just run one time when pdf is opened
 
hitCount = getHitCount("http://www.client.com/visitor.txt", fileExists); // get the counter from the text file
 
if (!fileExists) { // file does not exist then create it

createFile("http://www.client.com/visitor.txt"); // create a text file on the domain
 
var visitor.txt = 0; // initialize file to zero
 
saveFile("http://www.client.com/visitor.txt"); // save the text file to the domain
 
} // end if
 
hitCount = hitCount + 1; // increment counter
 
saveHitCount("http://www.client.com/visitor.txt", hitCount); // save it back to the domain

pdfOpened = true; // set to true so it wont run again
} // end if
 
. . . // code after . . .

How do I open, close, read and append files using Acrobat javascript, so I can read and write a file to a local file, or a remote location such as a text file on the web. Would like to have this work from Acrobat Reader v6 to current version. Any suggestions would be greatly appreciated.

My Product Information:
Acrobat Pro 9.0, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
And how is the file supposed to be saved on your server after each time someone opens it?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Adobe works very hard at protecting user privacy.

Why not look at using the analysis tools available to the web site?

George Kaiser

jmartinson
Registered: Feb 15 2011
Posts: 3
try67 wrote:
And how is the file supposed to be saved on your server after each time someone opens it?
As far as saving a file to the web site, that is exactly what I am trying to find out. How do you read a file from a web site, modify it, the resave, all from within Acrobat.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't, since the users can't upload a file by saving it.
The only way I can think of is to create a server-side script or application that will update a certain file or database record whenever a user clicks the link to open the PDF, and then have the PDF itself automatically read this information when opened and populate a field based on it.

Seems like a lot of effort to me for simple as mundane as a visitor counter.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

jmartinson
Registered: Feb 15 2011
Posts: 3
gkaiseril wrote:
Adobe works very hard at protecting user privacy.Why not look at using the analysis tools available to the web site?
Sorry if i was not clear. I do not have access to the web site. No access to analysis tools. The only thing I can do is provide a PDF. Everything needs to reside within Acrobat. That's why I need to be able to read and write a file to a web site. If I can't read or write to the client.com domain, then I will have to write to a different domain.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
jmartinson wrote:
Everything needs to reside within Acrobat.
In that case, it's probably not possible.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
Forget about reading and writing a text file directly, it's not going to happen.

What Reader can do is submit data to and receive data from a web server. So it would be possible to set up a web server to process each form submission, keep track of how many requests it gets, and return a number back to Reader as form data. This won't necessarily be easy or reliable, but it's really your only hope.