• 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
Guest
Aug 01, 2008 Aug 01, 2008

Copy link to clipboard

Copied

Here's a slightly different method, but it works..... (and, there is certainly no 'work around' for anyone to get data you don't want them to get!) <br /> <br />It uses the Action on Open (sorry, I don't know the 'official' name of this - I'll describe it below..) in the pdf to send the user to a server checking mechanism (in this case, a date checker - but you could do the same thing with lots of stuff...) <br /> <br />Here's how I set it up and it works great! <br /> <br />1. Start a new document that you can get a form field into (don't use LiveDesign for this - that's too fancy... - just make a document in Word that says ______ then print to pdf to get a nice simple pdf that you can edit directly in Acrobat) <br /> <br />2. Do a 'Run Form Field Recognition' and Acrobat will find the blank as a field. <br /> <br />3. Edit this field to have a "key" name (my example, I will use "today" which tells me this is the day that my document starts). <br /> <br />4. Under the 'Options' tab, make a Default Value of today's date (this will be the 'test against' date - for my example I'm showing how to expire a document in 30 days from creation date, but you could use anything you like - it is simple to modify!) <br /> <br />5. From the 'Format' tab, use the Select format category of Date. Use a date format you like (my example uses mm/dd/yyyy) Note that this MUST match the server side code described later). <br /> <br />6. For a 'live' document, you may want to go to the General tab and make the field Hidden as well as other things to not see the 'false' page, but that is outside the scope of this example. <br /> <br />OK, now on to setting up the document to automatically send this info to your server for testing... <br /> <br />1. Go to the 'Pages' view (click on the icon at the top left) <br />2. right-click on the page, select Page Properties. <br />3. Under the 'Actions' tab, select "Page Open" and "Submit a form" from the drop down boxes. <br />4. Enter a URL to your web page (see below) that does the checking (like http://mytestdomain.com/Scripts/checkexpiredate.php so it is easy to remember) <br />5. Check the HTML radio button. <br />6. Check the 'Only these...' button and then 'Select fields'. Make sure your "key" field is checked as well as the 'Include Selected' button (sometimes, for me, these weren't - I don't know why, so check it!) <br /> <br />Now, on to the server side... <br /> <br />Here's the code that goes into the php server file; <br /> <br /><?php<br />$day = date("d");<br />$month = date("m");<br />$year = date("Y");<br />$today = substr($_REQUEST["today"],3,2);<br />$tomonth = substr($_REQUEST["today"],0,2);<br />$toyear = substr($_REQUEST["today"],6,4);<br /> $tsp = mktime(0, 0, 0, $month, $day, $year);<br /> $tsd = mktime(0, 0, 0, $tomonth, $today, $toyear);<br /> $xdays = ($tsp - $tsd)/(24*60*60); // as calculated from dates<br />$maxdays = 30; //set this to whatever your 'expire from today' date is<br />if ($xdays >= $maxdays)<br /> //do what you like to tell the user it is expired<br />else<br /> //show the info you want them to see<br />?> <br /> <br />i (the info shown (or not) is outside the scope of this message, this is just a 'one way to make this work' example. In my system, I use a program called fpdf [http://fpdf.org] to create the pdf from 'scratch', building it to show the reader what I want them to see - whether it is a "Sorry, this is expired" document, or the data that they came for if the time hasn't expired.) <br /> <br />THAT'S IT!!! It works great and you can use it to do tons of stuff - just set the "key" on the original document and make the server code check whatever it is you want! <br /> <br />Pretty cool, I think! (and, it only took me, a novice programmer, about 3 hours to figure it all out!) <br /> <br />Best of success with it - enjoy!

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

Thank you for your time Steve.

Sorry I should have been a little more clearer, I am actually a designer (not a programmer)
so the above is a little overwhelming, are you able to set it out step by step?

Basically what I am trying to do is to set an expiration date on pdf files that I supply to my clients, so that once the file has expired it also can not be opened and edited via Photoshop/Illustrator should the pdf file land in the hands of another designer.

Is this possible?

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 ,
Aug 02, 2008 Aug 02, 2008

Copy link to clipboard

Copied

Use digital rights management (DRM) software.

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 02, 2008 Aug 02, 2008

Copy link to clipboard

Copied

Can you recommend any? I am a mac user. I don't have a big budget I am a freelancer?

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
Aug 02, 2008 Aug 02, 2008

Copy link to clipboard

Copied

try Adobe Document Center. you will need Acrobat 9 for a Mac (as I understand it - I have a client that told me that yesterday...)

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 ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

Hi,

I have posted the same problem in forum at:

M. Ahmad, "How to close a PDF doc opended in IE web browser using JavaScript?" #, 16 Sep 2008 6:44 a...

The example of my script works in pdf but not in browser, as most of you are having the same problem.

I will just say:
1) SetPageAction is not the right place to put your javascript for this purpose. As the script will not run untill file is not opened to that page or user does not go to that page.
2) I put this script as Document Level Script and that way it will run as soon as the file is opened.
3) Yes, the script can be added to one file or a group of files through BATCH PROCESSING. To do this you have to write another script to add this expiry script to the file/files automatically thorugh batch processing

4) I agree, it is not the true security but it is better than having nothing at all.

Thanks.
M.Ahmad

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 ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

Just be aware that any user who turns off JavaScript in their copy of Reader or Acrobat will not be restricted by this approach.

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 ,
Sep 18, 2008 Sep 18, 2008

Copy link to clipboard

Copied

Or any user with an other PDF viewer.

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 ,
Nov 19, 2008 Nov 19, 2008

Copy link to clipboard

Copied

I am interested in enabling the method of SteveMajors - Aug 1, 08 PST (#24 of 31). I have tried doing it, but it is beyond my knowledge of what i need to do or how to do it.

I don't know if or whether the options he advocated are necessary or not. I believe he was populating his form from his server, so disabling the script blocks access to the file as well. However, I would like to start with something simple like just the date being sent from my server.

I think my problem is in properly setting up the .php code and capturing it in acrobat (instruction #6).

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 ,
Dec 16, 2008 Dec 16, 2008

Copy link to clipboard

Copied

Hello,

Using SteveMajor's method of having the pdf checked against a script on a website, is it possible to cross check against the date a pdf is created on the user system with a expiry. To put it simply, i want a user downloading a copy of pdf from my intranet to be able to use it for 24 hours only (the counter starting from the time it is downloaded on the user system). This is to ensure some form of document control / version control.

Thanks!

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 ,
Dec 18, 2008 Dec 18, 2008

Copy link to clipboard

Copied

Allegra Pilosio, you said the script to expire PDF is working. To restrict opening the file in Illustrator or Photoshop, you can set the document secruity in PDF.

Use clt+D or Cmd+D, choose password security
Compactibility: Acrobat 3 or later
Encrypt All document contents
Set a Password
Printing Allowed: High Resolution
Changes Allowed: None

Thats it, people can't open your PDF in Photoshop or in Illustrator without knowing the password

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 ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Too bad we can't turn this around and somehow require Javascript is ON and then proceed. Maybe a pair of documents, first one that checks for Javascript that shows a link to the second document with the time sensitive data. Again, not a long term 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
Engaged ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Hi Melissa,

Yes, the problem with all these solutions is that in order to make them work JavaScript must be turned on. But your mention of a "cover" document explaning to the user that JS must be turned on is possible. There is an example PDF at-

AcroDialogs Product Page

Scroll down to the link for "Document License Dialog Example" to download it. If the user does not turn JS on then they cannot view the information under the "cover" layer. If JS is already turned on then they can view it.

Again, this is not an airtight security method, just a pretty good deterrent.

Hope this helps,

Dimitri
WindJack Solutions
www.windjack.com
www.pdfscripting.com

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 ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Not a big expert on wondows active directory but I am sure within active directory there is an option to force users not to be able to switch off programs like javascript.

The solution you have proposed here is actually quite handy. As mentioned this is really to help protect honest people. If you need something more secure I would suggest looking at windows active directory, although off course you need to be running this service in the first place.

Regards. Peter.

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 ,
Jan 11, 2009 Jan 11, 2009

Copy link to clipboard

Copied

Switching off JavaScript can be done from within Acrobat, so Active Directory can't prevent it. The layer option is good... I thought of another one -- hiding the pages in templates that are made hidden only when JavaScript is enabled and the script has not yet expired. Of course, an experienced user can display the pages themselves, but it would work for most.

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 ,
Mar 12, 2009 Mar 12, 2009

Copy link to clipboard

Copied

I'm not familiar with the JavaScript API, but is there a way to modify document appearance with the API? If so, then the document could be rendered in an unreadable format (e.g. white print on white background) and the JavaScript could check the date and modify the appearance. Thusly, if JavaSript were disabled, the document could be opened but not "used".

Yes, I understand that any of these measures can be likened to a lock on a screen door, but sometimes that's all you need to redirect the actions of the "almost honest".

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