Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem applying JavaScript on PDF files?

Status
Not open for further replies.

sepb

Technical User
Aug 1, 2002
11
NL
Can someone Please tell me,

How can I add a new button to the toolbar
in Adobe Acrobat 5?

The wish is to let the new button by clicking
on it execute a JavaScript on any PDF file that
Acrobat opens.

I have a JavaScript that I apply on PDF files
in a form box, witch shows the current date +
a number of extra days till expiration,
I got this far.

Now we I have to apply this manually to each
document, this takes a lot of time since there
are more than 3000 files to apply this to and
more files to come.

I am new with Acrobat and JavaScript, so anyone
who can help my on my way with this one?

Another option I was thinking of was to duplicate
the script to a selected group of PDF files, but
don't know how, anyone got some ideas?

Thanks.
 
Easiest way to do it is to write your script as a Batch Sequence. If you use the app.activeDocs method in your script to apply to all open docs, and specify in the batch sequence preferences that the script should run on all files open in acrobat, then you could open a batch of documents and run your batch sequence - it will apply the script to all of your docs. If you post a sample of the code you are running, it will be easier to see how to make it work. Ahhhhh, I see you have a machine that goes Bing!
 
This is the Script I am running in a Form box, for now.
any help wil be welcome, thanks.

var newdate = new Date();
var expdate = new Date() ;
with (expdate) setDate(getDate()+7);
var thisfieldis = this.getField("mydate");

var theprint = "Print date";
var theday = util.printd("dddd",newdate);
var thedate = util.printd("d",newdate);
var themonth = util.printd("mmmm",newdate);
var theyear = util.printd("yyyy",newdate);

var theexp = " Expiration date";
var thexday = util.printd("dddd",expdate);
var thexdate = util.printd("d",expdate);
var thexmonth = util.printd("mmmm",expdate);
var thexyear = util.printd("yyyy",expdate);

thisfieldis.value = theprint + " " + theday
+ " " + thedate + ", " + themonth + " " + theyear
+ theexp + " " + thexday + " " + thexdate + ", "
+ thexmonth + " " + thexyear;
 
Does the field "mydate" already exist in the documents that you are receiving, or are you creating this in each document? Ahhhhh, I see you have a machine that goes Bing!
 
Murgle,
I am creating this field in each document manualy.
 
O.K.

Go to File->Batch Processing->Edit Batch sequences and select New Sequence - name your sequence something like "Insert dates" or whatever you want, and click ok. Click 'Select Commands' and add execute javascript from the list. Click on the execute javascript in the right window and click edit, then insert the following script:

Code:
var thisfieldis = this.addField("mydate", "text", 0, [20, 60, 200, 20]);
var newdate = new Date();
var expdate = new Date() ; 
with (expdate) setDate(getDate()+7);
var theprint = "Print date";
var theday = util.printd("dddd",newdate); 
var thedate = util.printd("d",newdate); 
var themonth = util.printd("mmmm",newdate);
var theyear = util.printd("yyyy",newdate); 
var theexp = "  Expiration date";
var thexday = util.printd("dddd",expdate); 
var thexdate = util.printd("d",expdate); 
var thexmonth = util.printd("mmmm",expdate);
var thexyear = util.printd("yyyy",expdate);
thisfieldis.value = theprint + " " + theday 
+ " " + thedate + ", " + themonth + " " + theyear 
+ theexp + " " + thexday + " " + thexdate + ", " 
+ thexmonth + " " + thexyear;

Click on OK to return to the previous screen. Choose to run commands on a selected folder - ensure all the files you want to process are in there. You can choose to have them output to a different folder if required, and to save with a filename prefix or suffix to identify them as processed.

This will insert the specified information in a text field at the bottom of page 1 of every document in the selected folder - you can play around with the coordinates for the addField method to change where the box appears. You can also set default display options for your text box - refer to the javascript guide for more info.

Hope this helps.. Ahhhhh, I see you have a machine that goes Bing!
 
Sorry, forgot to say how to run it - just open Acrobat and got to File->Batch Processing-> and select your new sequence a run confirmation dialog box is displayed - click on ok to run.. Ahhhhh, I see you have a machine that goes Bing!
 
Murgle,
This will work for now, thanks for helping out.
 
Question,
Is it possible to add the Js code to the created
Field thru running a Batch Sequence, so each time
the document opens the Current date is displayed?

Because now when the Batch Sequence runs over the
selected files it only displays the Date of when
the Sequence was done.

If this is possible, do you have a sample of the
code to add to the current code?

Thanks for helping out!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top