Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Acrobat Scripting - Expire a PDF

Posted on 2006-06-20
11
Medium Priority
?
3,193 Views
Last Modified: 2008-01-09
Would anyone be willing to share or know of a script that could expire a PDF document after a certain amount of time.  I do not have the resources to purchase a DRM and am aware that users can change their own clock settings for a work around, but this functionality would be more then sufficient.

Ive gotten this far already but can't seem to get this to work.  I am new to JavaScript and hope someone can tell me where i am going wrong.

function Expire2()
{// Get the current date and time
var rightNow = new Date();

// Setup End Date
var endDate = new Date(2006, 5, 19);

// Calculate the time difference in milliseconds
var diff = rightNow.getTime() - endDate();

// Calculate the number of milliseconds in a day
//1 day * 24hrs/day x 60 min/hr x 60 sec/min x 1000 ms/sec
var oneDay = 24 * 60 * 60 * 1000;

// Calculate the number of days from current to end
var numOfDays = diff/oneDay;

if(numOfDays <= 0)
{
    app.alert("This Document has Expired.");
    this.close();
}
}


Any help is greatly appreciated.

Thanks - Mark
0
Comment
Question by:MHayes612
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 16945375
What is the problem with your script? What do you want it to do, and what does it do?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 16945473
After looking at your script for a bit, I think I found out what's wrong (and what you want to do with it). Try this instead:

function Expire2()
{
    // Get the current date and time
    var rightNow = new Date();

    // Setup End Date
    var endDate = new Date(2006, 7, 19);

    if(rightNow.getTime() > endDate)
    {
        app.alert("This Document has Expired.");
        this.closeDoc();
    }
}


As you can see, it's much shorter. There is no need to calculate the actuall difference. All you need to do is compare the current data against the date the document expires. Also, you did call endDate like a function - this is wrong, it's a variable, so the "()" is not needed. The last problem was that there is no function called close(), it's closeDoc().

You need the AcroJS guide from adobe's web site. Do you have access to that document?
0
 

Author Comment

by:MHayes612
ID: 16945509
I am not quite sure.  It doesn't seem to do anything.

Would like to be able to set the endDate prior to loading it into a pdf, so I will adjust that section on every PDF that i would have expire.

I am trying to OnOpen - run the script to determine the right now time.  Then, calculate the difference between now and my predetermined date.  If the result is less then or equal to 0, it should be expired and the alert should show up so it's not a surprise when it closes.

Any thoughts on that?

Thanks a lot for your quick response and any help you may be able to provide.

0
Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

 

Author Comment

by:MHayes612
ID: 16945545
Man that was quick!

You solved it before i even got to reply to your first.  I started with JS yesterday and i did skim through the AcroJS guide and it was quite helpful, but as I am sure you can see, I could have spent some more time on it.

Let me give that a shot and I'll let you know how it worked.

Thanks a lot!
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 16945546
To see what's wrong with your script, you can open the JavaScript debugger/console (Ctrl-J). It will show you one error at a time when you execute the script.

How do you call the script? Where do you store the script. You can create a document level JavaScript titled Expire2, and then call the Expire2() function right after you define it (as part of the same document level script).
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 16945563
You should get a "normal" JavaScript book. As far as I know, there is nothing available that just discusses Acrobat JavaScript. This means that you have to work with a book that describes the browser level JavaScript. Just ignore anything besides the core language (which is the same for browsers and Acrobat).
0
 

Author Comment

by:MHayes612
ID: 16945583
I have it as a doc level script, and i am hopingthat it runs everytime you open the file.

Not sure how to call the script though.  I agree with the book idea.  Just so happens that this was brought up yesterday and was doning my best to make it happen.

Thanks Again!
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 16945635
No, the document level JavaScript (if you use the function block that Acrobat gives you) is a function, and it will only run when you call it. The document level scripts get initialized when you start Acrobat. Edit the document level script and go all the way to the end - past the closing "}" and add the following line:

Expire2();

Save it, and open the document again (you may want to open your JavaScript console to see any potential errors). If you still don't see anything, add the following before the first line of your document level script (before the function... line):

app.alert("running document level script");

Save and try again. Do you see the popup?
0
 

Author Comment

by:MHayes612
ID: 16945707
That was it.  I was just about to ask that.

I included the expire2(); at the ensd of the script and it worked perfectly.

Thanks again, i really appreciate your help!
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 2000 total points
ID: 16945875
I see you are new to this site. Do you know how to close a question?
0
 

Author Comment

by:MHayes612
ID: 16945944
That was great Karl.

Thank you!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Acrobat’s JavaScript is a great tool to extend the application, or to automate recurring tasks. There are several ways a JavaScript can be added to the application or a document (e.g. folder level scripts, validation scripts, event handling scripts,…
Update 21-May-2015: I temporarily removed the source code to make major changes to the program. Regards, Joe In a previous Experts Exchange article, How To Rename-Move a Batch of PDF Files Based on Contents of the Files (http://www.experts-exchan…
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question