• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

How to set a PDF to expire (Working Script)

New Here ,
Mar 21, 2008 Mar 21, 2008

Copy link to clipboard

Copied

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 />}

Views

88.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 21, 2008 Mar 21, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 24, 2008 Mar 24, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 05, 2008 Apr 05, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

One tip is to always check the JavaScript console. There may be a
message in there about the problem.

Aandi Inston

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2019 Oct 25, 2019

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

>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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 07, 2008 Apr 07, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2008 May 09, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2008 May 09, 2008

Copy link to clipboard

Copied

These instructions apply to PDFs NOT created by LiveCycle Designer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2008 May 09, 2008

Copy link to clipboard

Copied

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...)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 09, 2008 May 09, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2008 May 12, 2008

Copy link to clipboard

Copied

Yes, I understand there are obvious ways around it, but it is better than having no alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 12, 2008 May 12, 2008

Copy link to clipboard

Copied

The alternative is Adobe LiveCycle Policy Server.

EDIT: Sorry, it's been renamed Adobe LiveCycle Rights Management for the LiveCycle ES Suite.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2008 May 18, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 18, 2008 May 18, 2008

Copy link to clipboard

Copied

And Acrobat JavaScript may not work on many PDA and other wireless devices that might display content.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 20, 2008 May 20, 2008

Copy link to clipboard

Copied

They may be "worthless" solutions for non-internet-connect scenarios, but that doesn't make the implementation any more secure. It's still a laughably insecure approach to expiring a document. Unless you are in complete control of the viewing environment, I know for a fact that a lot of corporate deployments of Acrobat default to JavaScript turned off - which means to them, your document never expires. A lot of home users turn JavaScript off too because they don't "trust" JavaScript. Not to mention all the people that use non-Adobe viewers (Foxit Reader for example) that may not handle the JavaScript correctly and cause unknown results.

There is no perfect solution for expiring a PDF in a non-internet-connected scenario. If you can't control the timechecking in a known-safe server environment and have to rely on information from the local system, your security it lost since anybody can do anything to the local system. If you're looking for something showy that will make people feel warm and think that you have some form of security on your documents, use the above script. But I would be weary about passing it off, especially in a professional environment, as "secure". Anybody who wants to spend 5 minutes on Google looking at PDF security will realize your "security" is a complete sham and that could reflect badly on you.

The best option to secure a PDF in a non-connected environment is to apply document encryption and only give the password to those who need to view the document.

Oh and LiveCycle Rights Management ES has plenty of fallback configuration options for how to handle non-connected environments with policy-protected PDFs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2008 Jun 16, 2008

Copy link to clipboard

Copied

Do you know how to add a specific time to the expiry?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 16, 2008 Jun 16, 2008

Copy link to clipboard

Copied

You need to add the variables for hours, minutes, seconds and milliseconds to the code. A generalized version that will work with omitted time elements follows.

function CheckExpiration(LastYear, LastMonth, LastDate, LastHour, LastMin, LastSec, LastMS) {
// document level function to see if passed date less than today's date
// check that numbers are passed as parameters
if (isNaN(LastYear) ) LastYear = 1900;
if (isNaN(LastMonth) ) LastMonth = 1;
if (isNaN(LastDate) ) LastDate = 1;
if (isNaN(LastHour) ) LastHour = 0;
if (isNaN(LastMin) ) LastMin = 0;
if (isNaN(LastSec) ) LastSec= 0;
if (isNaN(LastMS) ) LastMS = 0;

LastMonth = LastMonth - 1; // adjust the passed month to the zero based month
// make the expiration date time object a numeric value
var myDate = new Date( Number(LastYear), Number(LastMonth), Number(LastDate), Number(LastHour), Number(LastMin), Number(LastSec), Number(LastMS) ).valueOf(); // convert passed expiration date time to a date time object value

// get the current date time's object as a numeric value
var today = new Date().valueOf();

// return logical value of the comparison of the passed expiration date value to today - if true document has expired
return (myDate < today);
}

// the following code has to be executed after the above function is defined

// edit following fields
var ExpireYear = 2008; // 2008
var ExpireMonth = 3; // March
var ExpireDate = 21; // 21st
var ExpireHour = 12; // noon
var ExpireMin = 0;

// the following code has to executed after the above function and variables are defined.

// test for expired document based on result of the passed time elements compared to the current date and time as returned by the CheckExpiration() function.
if (CheckExpiration(ExireYear, ExpireMonth, ExoireDate, ExpireHour, ExpireMin) ) {
this.closeDoc(1);
app.alert("This files has expired.",1,0,"Expired");
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 01, 2008 Aug 01, 2008

Copy link to clipboard

Copied

Yes the script does work to expire the pdf, however you can still open the pdf file through Photoshop or Illustrator even though it has expired. Is there any other solution?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines