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

Javascript to look for new version when PDF opens.

DanB
Registered: May 8 2007
Posts: 34

Is there a way to add Javascript to a PDF Form that makes it check against a url to see if the form has been updated when it is opened. If so, can the user be notified or can the updated PDF be replace the the one saved on the users machine.

Thanks.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can create a workflow that does something like this. The specifics of how it's done and how much can be implemented depend on a lot of parameters. Is this an in house or a public system? What version and type of Acrobat will the user's have on thier desktop? Can you install a program on the user's system? Can you write a Server Side script? Do you already have a document management system?

This type of project is not trivial to build. It can be more or less difficult depending on how sophisticated you want it to be. Unless you want something really simple where the user has to do some work, it's the sort of thing you either have a team of developters working on or purchase an existing system from a 3rd party.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

DanB
Registered: May 8 2007
Posts: 34
thomp wrote:
Is this an in house or a public system?
In House. Note our house is a public school district with 80 plus physically seperated locations that share a Network.

thomp wrote:
What version and type of Acrobat will the user's have on thier desktop?
Acrobat Reader. Versions: a wide range

thomp wrote:
Can you install a program on the user's system?
Sure I can make one available for download.

thomp wrote:
Can you write a Server Side script?
Sure depending on the language.


thomp wrote:
Do you already have a document management system?
We do only for our internal use. I cannot make it available without a huge expense.

As I understand it, I cannot prevent a user from saving a copy of a PDF on a local drive. My goal is to make sure that if they open a PDF, they at minimum are advised that the PDF is or is not obsolete. Again these are forms and we don't want bad forms used.

So what do you suggest?

Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, you have a perfect situation for being able to test the document version against a standard. Almost any version of Reader (going back to Acrobat 3) can send an HTTP Request to a server script and recieve an HTTP Response. Given that the users have a variety of Reader versions, this loosely coupled method is the best way.

So to start off you'll need a server script (any language) that can recieve FDF data in the body of an HTTPRequest, parse the FDF for the DocID (or other info), Test the DocID (or other info), and then return something in the HTTP Response.

Each PDF has a unique DocID. Look up "Doc.docID" in the Acrobat JavaScript Reference. The Permanent Identifier part of this docID can be used for version control. If you wanted a method that was more under your control you could place a readonly field on the form that shows the version number. I like this method best.

To do the version check, place some code in a Document Level script to call "this.submitForm()". This function sends an HTTPRequest to the specified URL. Set the "cSubmitAs" input to "FDF". The FDF will be placed in the Body of the request and contain any field data on the document, the file name, and the DocID.

On the Server side you'll need the FDF Toolkit to parse this information out of the FDF. This is a free download on the Adobe Developer site, www.adobe.com/devnet.

There are different things you could send back. FDF can contain JavaScript so the return FDF could simply be an Alert box telling the user to update the form. I use this one a lot. You could also send back the entire new document. The details for implemented these methods are complex so you'll need to spend some time working them out.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

DanB
Registered: May 8 2007
Posts: 34
Thanks Thom,

I now have something to work with. I might be back with questions as I try to do this.

Dan
DanB
Registered: May 8 2007
Posts: 34
Thom,

I did a little reading about FDF and I'm not sure if that is what I'm looking for. I should have picked up on this when you mentioned "Document Level script to call 'this.submitForm()'".

I'm not looking to capture any data. The forms we want to create, are to be completed and printed with the entered data but not saved with data. I have one we developed that works this way except I cannot prevent the user from saving the blank form.

My objective is to have the blank form "call home" (home being a url) and either notify the user that the form is obsolete if indeed a new version exisits or open the new version for use.

I was hoping there would be some simple Javascript I could add to the form that would do this perhaps in an event something like an HTML onLoad event.

Thanks

Dan
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
And how are you going to communicate the unique document ID to the web page script that will verify that your PDF is the most current?

There are very few OS exits to the OS within Acrobat JavaScript.

George Kaiser

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In the methodology I described the "submitForm" function is being used to call home to do a version check. It is not being used to submit data. Using "submitForm" and FDF data allow you to send data to the server for version checking and to respond in a variety of ways, from doing nothing at all to seemlessly providing the user with a new form.

But there is another option. Use the "app.launchURL()" function to send version data to an URL in the query string. Unfortunately this approach will always display a web page.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script