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

Close Document after expiration date.

Gattaca714
Registered: Dec 16 2009
Posts: 25
Answered

Does Javascript or Acrobat have the capability to create a document which will expire after an X number of days?
 
For instance, an argument that says:
 
IF todays date is greater than 10/31/2010 then document close.
  
?????

My Product Information:
Acrobat Pro 9.3.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, But it's not supper secure. Document level scripts are run when the PDF is opened. So, a script can be created that checks the current date against some hard coded value, and then closes the PDF if the date has been passed. This scheme can be made more secure by added two more features to the PDF. First, adding security to the PDF so that the script cannot be removed or modified, and second, by adding a watermark that obscures the page content. Watermarks are associated with what's called an OCG, which can be turned on and off with a script. In this case the document script would turn the OCG off (exposing the underlying content) if the expiration date had not been reached. This allows you to protect the document in the case where either JavaScript is turned off, or the viewer does not run JavaScript. In these cases the pages would only show the watermark and not the underlying content.

Here's an article on OCGs:
http://acrobatusers.com/tutorials/2006/create_use_layers

And you'll find an example of something similar here,
Select the "Document License Dialog Example":
http://www.windjack.com/product/acrodialogs/


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

Gattaca714
Registered: Dec 16 2009
Posts: 25
This is the script I ended up with:

function Expire()
{
// Get the current date and time
var rightNow = new Date();
// Setup End Date
var endDate = new Date("October 21, 2010 23:59:59");
if(rightNow > endDate)
{
app.alert("This Document has expired, please contact the IT department for additional access.", 1, 0);
this.closeDoc()
}
}

// execute check expiration code
Expire();

Thanks for th lead Thomp.
pdfer
Registered: Dec 23 2010
Posts: 28
I've used this code and it works great. But, what would you do if the person (viewing this doc) sets their computer's clock and date backwards to last year, last week or whatever date and time prior to the function Expire() code. As long as they change the date to any thing prior than you've written in the Javascript, makes this functionExpire useless. Rendering your doc helpless.

What I want to do is - write a Javascript that would expire if the computer's date was altered. If the function Expire() closes the on a specific date then there's got to be a script that would compare the date and year of the Javascript to the computer's date and year and if they don't match then do function Expire(). That would be great.

If any one out there knows any one that knows any one that knows any one that knows how to write this code, please, let me know. That's all I need. Then my work can be viewed and I'll feel a little better about sharing my work.

Jackson C.

UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
@pdfer : That is impossible with a script - the *only* way JavaScript can get the current date is to ask the operating system, and the user can set that to anything they want.

To expire a file based on a genuine timestamp you must use a DRM solution such as Adobe LiveCycle, which verifies the time at a remote server and works irrespective of what the user has done, even if JavaScript is disabled.

There is currently a limited but free service using LC called Adobe Document Center, which you can use to test the process on your own documents. LiveCycle itself is an enterprise-class solution with a corresponding price tag.