expire a protected adobe pdf How to expire a protected adobe PDF adobe acrobat pdf with expiry 862x728

How to expire a protected adobe PDF

Glenn Blog 13 Comments

Adobe PDF Portable Document Format is widely recognised as a preferred method for capturing and sending electronic documents in exactly the intended format. You can protect PDFs and limit copying, printing or even password protect opening them, but right now you can’t set them to ‘expire’ so that they can’t be opened / read past a certain date. That’s a really handy feature if you are sending a document like an offer / proposal that is time dependent. You might also want to limit the documents reach to undesirables / third parties that may be looking to use your spec / intellectual property and rip-off your content.

The following Javascript approach to expiring a PDF document has it’s limitations (which I’m purposefully not going to outline), but it does provide a neat interim approach to this problem.

Here’s how to expire your PDF on a certain date | Open a Dialog and then automatically Close

  1. Create your PDF (‘Print as PDF’ is a quick way to do this outside of Adobe’)
  2. Open up your PDF in Adobe Acrobat Pro DC (Part of Adobe Creative Suite and required for this advanced editing)
  3. Click on ‘Tools’ and then ‘Javascript’ – Add
    adobe-acrobat-add-javascript expire a protected adobe pdf How to expire a protected adobe PDF adobe acrobat add javascript 300x236
  4. In the Javascript Menu click on ‘Document JavaScripts’
    adobe-acrobat-document-javascripts expire a protected adobe pdf How to expire a protected adobe PDF adobe acrobat document javascripts
  5. This opens up the Document Javascript Dialog now under ‘Script Name’ Add the name ‘Expiry’ and click ‘Add’
    adobe-acrobat-document-javascript expire a protected adobe pdf How to expire a protected adobe PDF adobe acrobat document javascript
  6. In the JavaScript Editor delete everything so that it’s blank and then enter the following JavaScript
    function Expiry()
    // Get the Expiry Date
    var ED = util.scand("dd/mm/yyyy","14/06/2016"); // Expiration date is 14th June 2016. Change this date to suit your needs
    // Get Today's Date
    var TD = new Date();
    // Validate and take measures!
    var diff = (((((ED.valueOf() - TD.valueOf()) / 1000) / 60) / 60) / 24); // Days difference
    if (diff < 1) {
    // Now the drastic thing...
    app.alert("Sorry this document has now expired. You cannot use this specific document any further.\n___________________________________________\n\nPlease contact someone@yourdomain.com for an extension. Thanks.", 0, 0);
    // Dont Save and Close Document
    DontSave = true
    // execute check expiration code
  7. On the 4th line of the code change the date of “14/06/2016” to the expiry date that suits your needs and then enter your own message from line 13  and click ‘OK’
    adobe-acrobat-document-javascript-editor expire a protected adobe pdf How to expire a protected adobe PDF adobe acrobat document javascript editor
  8. That completes the code for the expiry and will open the expiry message when the date entered is passed and will then close the document, however we still need to protect the document.
  9. To protect your document on save Go to ‘File > Properties’  and click on the ‘Security’ tab
  10. Change the ‘Security Method’ to Password Security and then select your Security Restrictions. We generally don’t want people to Copy / Edit the Text, but we do want them to Print in High Resolution so we set our documents up like so:-
    adobe-acrobat-password-security-settings expire a protected adobe pdf How to expire a protected adobe PDF adobe acrobat password security settings
  11. Once you have made your selections add in the ‘Change Permissions Password’ and click ‘OK’. You will then be prompted to ‘.. confirm the Permissions Password’ and then hit ‘OK’ and come out of the Document Properties by clicking ‘OK’ again.
  12. Now go to File > Save As and Save your document. You are now done and can close your time dependent PDF document for distribution.

This is the finished article which will close shortly after the prompt is displayed:-

adobe-acrobat-pdf-with-expiry expire a protected adobe pdf How to expire a protected adobe PDF adobe acrobat pdf with expiry

About the Author
expire a protected adobe pdf How to expire a protected adobe PDF 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g


A highly experienced Web Designer / Web Developer (Webflow, WordPress, Weebly & Custom), Front-end / Back-end Developer & New Media Specialist, with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries, built up over a number of years.

  • Jamie

    Hi Glenn!

    Thanks for this article – really helpful!

    I was wondering how you would adapt the code above so that the PDF document expires a certain number of days after it is either first downloaded (from a website) or opened?


    • Hi Jamie
      The file is protected so that the document/document script can’t be modified. This also means that a script can’t write to and save to the file. So ‘todays’ date can’t be written in JavaScript and therefore as far as I know this is not achievable on this basis.
      Best Regards

  • alex

    Thanks Glenn,
    One question: What would happen if the user does the trick to change his computer’s date to an early date such that it is before expiry date? Would that allow him to see the protected file?

    • I haven’t gone that far in tests, but yes in practice if the document is open on a users machine then it works from ‘today’s date’. There are limitations to this technique, but They are generally beyond the average user. The other option is a document delivery network and they are seriously expensive.

  • aze

    hi there’s a syntax error at line 5…

    • Line 5 is blank, but the code seems to have got a bit jumbled via the code changing to HTML. I’ve updated this. Thanks!

  • Frank

    Hi There,
    Does this also work for a PDF made via Nitro Pro?
    Thanks for your swift response.

    • Hi Frank
      I’m not sure it’s only tested on Adobe Acrobat (Pro), but if you can add Javascript into the document and then protect it with a password for editing then it could be feasible as the end result is a ‘PDF’. Give it a whirl and let us know how you get on.
      Best Regards

  • Frank

    Hi Glenn,
    I just tested it in Nitro Pro and it works fine. Thanks for sharing this solution!!

    • Good stuff – glad it worked for you!

  • JS90

    Thank you for such a helpful post. Two questions: if my monthly/annual membership with Adobe Acrobat Pro DC expires, will this in any way affect the PDFs that have expiry dates on? Perhaps it wouldn’t, but I wondered if they would then all be once again available to read. And secondly, do you have any advice or thoughts on how to make it impossible for a reader to actually download the PDF? Just for security purposes, I would love to be able to restrict that. Thank you for your hard work.

    • Hi
      1. Absolutely no effect. Once the PDF is created that’s that and the document will expire when set.
      2. Good question. if you are distributing the file via Google Drive for web then you can disable downloading, printing, and copying. To use the feature, open the sharing dialogue from any Google Drive file and click on Advanced in the lower right corner. Check the “Disable options to download, print, and copy for commenters and viewers” box and click “Save changes.” Google Drive is part of Google G Suite (https://slickmedia.co.uk/google-g-suite/) and worth a look.

  • Sanchari

    thanks. But how can I set dynamic expiry date from a PHP application. I exactly need this functionality to implement but expiry would be dynamic i.e. based on user registration. Can any PHP application communicate with PDF javascript? Please help.