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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using script to perform saveAs new filename

Status
Not open for further replies.

Murgle

Technical User
Oct 23, 2002
2,097
GB
I wish to have a button activated script which will create a copy of the current document, under a different filename in a subdirectory of the current document. I tried this using the saveAs method, but could't get it to work. Can anyone help with the saveAs method, or alternatively is it possible for me to use the extractPages method for all pages in the document to do the same thing?
 
If you read your Java Script PDF it does say this is explicitly blocked. For security reasons. AND I can only agree - we don't want viruses allied to Acrobat.

FWIW apparently there is a way that the Acrobat writer (NOT the reader) can be made to run virus-like script. So be vigilent.
 
Actually, it can be done. What you are referring to is security that prevents this script from running within a document. As the javascript guide says:

Security : This method can only be executed during batch, console, or menu events.
See the Event Object for a discussion of Acrobat JavaScript events.


Fine - create the script as a batch sequence, and create a button within your document which calls the batch sequence as an execute menu command on mouse up. The problem I was having was not to do with this, as I am well aware of the security restrictions, it was with the app.activeDocs method. Under 5.05 it is necessary to have the following document script:
this.disclosed=true;

otherwise app.activeDocs returns nothing (the default is this.disclosed=false;)
 
Menu events seem to stop on text entry - I used the menu event to go to page to get round a specific problem and all I get is the dialogue box. Manual entry from there.
"Save As" I presume is one better in that it it may offer the original filename but how to you automatically press the "Yes" key? Answers to both these problems would be instructive.
I have seen discussions about external VB workarounds - using Key mimic instructions - done it myself with Outlook, and it works but it took a while to get all the circumstances together.
 
I don't actually call 'Save as' from the menu commands, I call a batch sequence script which uses the saveAs method as below.
Code:
/* Save as new */
var aDocs = app.activeDocs;
var myDoc = aDocs[0];
var ttl = this.getField("Title");
var tv = ttl.value;
var pat = this.getField("pat");
var patv = pat.value;
var offeng = this.getField("offeng");
var offengv = offeng.value;
myDoc.saveAs(patv + tv + ".pdf");
var num1 = this.getField("Plant Change PC");
var num1v = num1.value;
this.mailForm(true, offengv, "", "", (num1v + tv),"The above Plant Change has been initiated and requires registration");

The new filename and cPath are determined by extracting field values from the current document, as are the recipients for the email. When the 'submit' button is pressed a run sequence confirmation box is presented - the user can either click ok or cancel. It is worthwhile noting that access to the document is controlled and limited to a specific group of users on a LAN, administered by me, who are all at one geographical location - this has made it possible for me to set up the batch sequence on each users machine. This would be a difficult process to manage for something that was more widespread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top