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

    Inspiring
    May 18, 2008
    And Acrobat JavaScript may not work on many PDA and other wireless devices that might display content.
    Participant
    May 18, 2008
    Two questions regarding the JavaScript approach...

    1) Is there a way to add this bit of JavaScript information to a pdf file in a batch fashion via Java, Python, etc.? I would like to add this to a build process in Ant. Any suggestions?

    2) The responses regarding how insecure this is and to use the client/server approach seems worthless for a situation where the pdfs may never see internet connectivity. The only reason for using pdfs is for mobile users of my information. That is first and foremost why I need some document-embedded solution. Are there any document-embedded solutions that are known that do not involve client/server communication?

    Thanks a lot for any assistance.
    Patrick_Leckey
    Participating Frequently
    May 12, 2008
    The alternative is Adobe LiveCycle Policy Server.

    EDIT: Sorry, it's been renamed Adobe LiveCycle Rights Management for the LiveCycle ES Suite.
    Participant
    May 12, 2008
    Yes, I understand there are obvious ways around it, but it is better than having no alternative.
    Patrick_Leckey
    Participating Frequently
    May 9, 2008
    You do understand that this method provides no security at all, right?

    Turning off JavaScript or changing the date on your computer will circumvent any form of "security" this script may seem to provide.
    Participant
    May 9, 2008
    Thanks Geo - that is my issue.

    Does anyone know if there is there a way to generate silimar results in designer? (an expiration by date, or number of times opened etc...)
    Inspiring
    May 9, 2008
    These instructions apply to PDFs NOT created by LiveCycle Designer.
    Participant
    May 9, 2008
    When I attempt this.. I get to step 4 and then it will not allow me to Add...

    Is there a specification I am missing... a file type.. or reason my PDF won't allow me to edit such things.
    Patrick_Leckey
    Participating Frequently
    April 7, 2008
    Good catch, Aandi. Hadn't occurred to me until now. closeDoc does not work in a browser window, you're right. Since AcroJS stops processing at the first error, you never get the app.alert message because closeDoc comes before it, and you see the document because closeDoc can't close a browser window.

    Just another reason why "JavaScript-based Document Security" is a misnomer and why this script really shouldn't be used for any sort of security - all you have to do is open the document in a browser to bypass the security.
    April 7, 2008
    Thanks for the message with details!

    When I turn on the JavaScript debugger in Acrobat Pro, I get this message (whether the 'clean' file or the 'expired' - same message).

    Don't know if it has anything to do with the issue, but it is what it is...

    Acrobat Database Connectivity Built-in Functions Version 8.0
    Acrobat EScript Built-in Functions Version 8.0
    Acrobat Annotations / Collaboration Built-in Functions Version 8.0
    Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
    Acrobat Multimedia Version 8.0
    Acrobat SOAP 8.0

    NotSupportedError: Not supported in this Acrobat configuration.
    Doc.closeDoc:17:Page undefined:Open

    As for being a 'programmer' - that ain't gonna happen.... I've been in computers since 1978 (Apple ][ days...) and found out a long time ago that I don't think like a programmer (it takes a special person with special skills and dedication, IMHO...), though I do like to 'hack around' and try out the simple stuff on my own.

    What I'd really like to do/have/find is someone that totally understands this stuff as well as the business side of things that will stick to being 'on staff' (what we find is that "programmers" tend to get the majority of the project done, then something else comes along.... - certainly on the bigger projects.... we have a mostly-written back-end project done in perl, but now the programmer isn't answering the phone, or not getting into it to finish....

    That's why I like to 'hack' - small changes are something I can do myself.

    Anyway, I think this has gone as far as I want to go with it - something that 'kinda' works on one out of 6 computers seems to me to be a FAILURE, not an OPTION....

    Thanks for your replies and the instructions on how to at least look at the debugger thing.

    All the best.
    Participating Frequently
    April 7, 2008
    >NotSupportedError: Not supported in this Acrobat configuration.
    >Doc.closeDoc:17:Page undefined:Open

    Ok, if we refer to the JavaScript Reference there may be some clues
    there. It's basically saying that closeDoc (which you'll find in the
    code somewhere) isn't being allowed, usually for some security or
    impracticality reason, rather than because you didn't ask right.

    But no: no useful notes. It may be that you are trying to do this in a
    browser document? You can't close the document window for a browser.
    >
    >As for being a 'programmer' - that ain't gonna happen....

    It's already happened. You may feel you're just doing copy-and-paste
    programming - but an increasing number of "programmers" actually
    believe this is all there is to programming. I respect your judgement
    that you don't want to be what you see a programmer as being, but you
    are doing programming tasks, just as someone who has to saw a piece of
    wood is doing carpentry tasks - and the saw is still sharp!

    What I'm saying, I guess, is that trying to get this working while
    simultaneously saying "No! I don't want to learn this stuff" isn't
    going to work.

    Aandi Inston