Skip to main content
Participant
March 21, 2008
Question

How to set a PDF to expire (Working Script)

  • March 21, 2008
  • 35 replies
  • 89952 views
Here is a little script I made up the other night. You can use it to allow a PDF to be opened only until a set date. I use this for when my employees go to service a customer. I want them to be able to see the customer's information, but only for 24 to 48 hours.<br /><br />CheckExpiration()<br /><br />function CheckExpiration()<br />{<br />/*-----START EDIT-----*/<br />var LastDay = 21<br />var LastMonth = 3<br />var LastYear = 2008<br />/*-----END EDIT-------*/<br /><br />/* DO NOT EDIT PAST HERE !!! */<br />var today = new Date();<br />var myDate=new Date();<br />LastMonth = LastMonth - 1<br />myDate.setFullYear(LastYear,LastMonth,LastDay);<br /><br />if (myDate<today)<br /> {<br /> this.closeDoc(1);<br /> app.alert("This files has expired.",1,0,"Expired");<br /> }<br />}
    This topic has been closed for replies.

    35 replies

    April 7, 2008
    Aandi,

    Thanks. Sure wish I knew what that was, or where to find it....

    guess it's back to the 'search the help file' again.....

    I really do thank you (and all the experienced folks out there) for your tips/guidance, however, PLEASE remember that I got Adobe Acrobat last week (haven't even received the CD yet...) and I'm about as lost as anyone can get! (step-by-step is highly appreciated... - not only for me, but in reading the forums, it seems there are many more out there as bad, if not worse off than me!)

    Steve

    P.S. (added after doing some searching) I found that "Javascript console" is something that browsers have.... check out http://www.webmonkey.com/06/19/index3a.html for a nice page... They say, "In IE, go to Tools > Internet Options and choose the Advanced tab. Make sure the check box for "Display a notification for every script error" is checked. " I'm off to try that....

    P.P.S. Turned that on, tried the 'expired' page and nothing special - was able to read the entire thing...
    Participating Frequently
    April 7, 2008
    They now call it the JavaScript debugger in Acrobat Professional, look
    under Advanced > Document Processing. Not sure about other products.

    Browsers have a different JavaScript environment to Acrobat; each one
    may have a console, but when running Acrobat JavaScript you need the
    AcrobatJavaScript console.

    Please remember that you are now learning to be a programmer, and that
    isn't something you can get good at in a day, a week, or a month; nor
    through a handful of tips.

    Aandi Inston
    ls_rbls
    Community Expert
    Community Expert
    October 25, 2019

    Hit Ctrl+J keys in your keyboard to open up the jscript console 

    April 7, 2008
    Thanks, Aandi.

    I clearly understand that and have tried to tell him, but 'pictures speak louder than words' and seeing it happen (or not) will likely help him understand everything.

    What I have found (by studying the help files all weekend) is ONE way to implement this Java code (I'm not sure if it is 'right'...) that WORKS on ONE OUT OF SIX computers...

    I placed the code on the Page Properties of the first page (steps below for the 'newbies' like me...) - it was really simple once I found out how to do it...

    **** STEP BY STEP FOR OTHER NEWBIES ****
    To use the Java script as described in this post (at least, as I did - maybe someone else will have better ideas and describe it for us...)

    1. click on Pages on the left sidebar
    2. right-click on the first page
    3. select Page Properties, Action
    4. under Select Action choose Run a Javascript
    5. click Add
    6. in the window that pops up, copy/paste the code from the post
    7. click OK, OK to get back to the doc (change the Javascript later if you want, this is just 'initial testing'...)
    8. IMPORTANT! Save the file under a different file name (or you may not be able to open it later!)
    *********END OF STEP-BY-STEP*********

    I included #8 because now, when I try to open the 'expired' doc in Acrobat, I get the 'expired' message and can't open it at all, but in IE, I see the document - on 5 of my 6 computers (including the one that Acrobat won't open!)

    So, even though this is not 'secure' nor a 'pro' solution, please help me understand if a) I did this right and b) why it only works on the ONE computer (running Win 2000 Server and IE 6 with Reader 7) and not on any others (incluing NT, XP, Vista and 2000 Pro with various versions of IE and Reader).

    Thank you for your time.

    What I would really like to see is your reply with DETAILS on how to test this and both 1) learn how this stuff is done and 2) show my associate the difference in turning it 'on' and 'off'.

    Best regards

    Steve Majors
    Participating Frequently
    April 7, 2008
    One tip is to always check the JavaScript console. There may be a
    message in there about the problem.

    Aandi Inston
    April 5, 2008
    If a fairly technical person with nearly no coding skills (for example, a person like ME...) wanted to use this script, just what does it take to implement.

    I totally understand that it is limited to 'keeping honest people honest' and has nearly zero "real" protection.

    However, I have a request from an associate to protect pdfs by date and he wants it quick and cheap..... (we don't have tons of servers or want to acquire the know-how of maintaining them ourselves).

    We've been trying the ADC, but have issues with it opening files on a Mac. Other solutions look nice (FileOpen, etc.), though they are a bit pricey-er than we'd like since the main thing is simply to have docs expire on a given date (we like the 'by user' features, but that's really not a huge requirement at this time).

    Thanks for your input.
    Participating Frequently
    April 7, 2008
    Be very sure to explain to your associate: here is a solution, but the
    end user only has to turn off JavaScript to avoid it.

    Aandi Inston
    Patrick_Leckey
    Participating Frequently
    March 24, 2008
    Actually that was the name for the LiveCycle version 7 suite. In version 8 the product that provides this functionality is called LiveCycle Rights Management.

    http://www.adobe.com/products/livecycle/rightsmanagement/

    It does not use scripting of any sort and so it cannot be so easily disabled as by removing a check from a preference setting or by changing the year on your clock to 2007 (since the script above does not have a start date to validate against either). It is embedded into the document and forces Acrobat or Reader to validate against your Rights Management server before you are allowed to open the document.
    Patrick_Leckey
    Participating Frequently
    March 21, 2008
    Well, as long as the user doesn't change the date on their computer or turns off JavaScript in Acrobat. If a user does either of those things, the form will open regardless of your script.

    Adobe LiveCycle Policy Server provides this functionality in a server / client setup so that it authenticates the user, date and time against a trusted server before the form is opened.