Q: I want to set an expiration date on a PDF document so that the PDF expires after a certain amount of time and can no longer be open. Is it possible in PDF Studio?

A: There is no concept of expiration date defined in the PDF specifications format. And unless you are using a sophisticated document storage service or a Digital Right Management (DRM) server such as LiveCycle, you can’t really have this level of control over PDF documents.

There is a workaround that involves using JavaScript which is not guaranteed to work in all PDF viewers but should work in PDF viewers that support JavaScript (when JavaScript has been enabled). This includes the most popular PDF viewers including Adobe Reader, Foxit, etc…

In PDF Studio, you can set an expiration date on a PDF documents using JavaScript by following the instructions below:

  • Open the document that need to set expiration dates
  • Make sure the Pages pane is showing on left side, you can enable it by going to View -> Tabs -> Pages
  • Right click on the first page and select Page Properties
  • Click Add button
    pageproperties
  • Click Action dropdown -> select Javascript Action
    java
  • Copy and paste the following scripts into the box
    function Expire()
    {
    // Get the current date and time
    var rightNow = new Date();
    // Set End Date to 11/28/16 for instance
    var endDate = new Date(2016, 11, 28);
    if(rightNow.getTime() > endDate)
    {
    app.alert("This Document has Expired.");
    this.closeDoc();
    }
    }
    Expire();
  • Click OK and Save the document
  • You can test this by changing your system date & time and opening the PDF in Adobe Reader. The popup will display and select OK will close the document. Be careful to revert back to the current date and time!

Note 1: Make sure to disallow the permission to edit the PDF document or your users could simply remove the JavaScript.

Note 2: Support for the method “closeDoc” was added in PDF Studio 12 and so the document will close as expected in version 12. In PDF Studio 11 and below,  the document will not close, it will remain open.