Copy link to clipboard
Copied
Hi All,
This is my first attempt at using Javascript...
I am attempting to create a Save As button on a form that will:
So far I have been fairly successful. I have been able to do a silent save, saving to a specific location and saving the file name based on fields. I need help building the rest of the functionality into the code if possible.
Thanks in advanced!
-------------------------------------------------------------------------------------------------------------------------
The code I have so far is:
Trusted Level Function
saved in Notepad under the Adobe / Javascript folder
mySaveAs = app.trustPropagatorFunction(function(doc,path) {
app.beginPriv();
doc.saveAs(path);
app.endPriv();
})
myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) {
// Privileged and/or non-privileged code above
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
// Privileged and/or non-privileged code below
});
PDF Button
Code under button that is executed on Mouse up click
// build file name
var myFileName = getField("Work_Pack").value + " - " + getField("Form_Name").value + " - " + getField("Todays_Date").value + ".pdf";
// add folder name
myFileName = "/c/temp/Saved Forms/" + myFileName
myTrustedSpecialTaskFunc(this, myFileName);
this.closeDoc() ;
-------------------------------------------------------------------------------------------------------------------------
FYI for those interested I used the following:
Trusted Level Function
saved in Notepad under the Adobe / Javascript folder
mySaveAs = app.trustPropagatorFunction(function(doc,path) {
app.beginPriv();
doc.saveAs(path);
app.endPriv();
})
myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) {
// Privileged and/or non-privileged code above
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
// Privileged and/or non-privileged code below
});
PDF Button
Code under button that is executed on Mouse up cl
...Copy link to clipboard
Copied
Points 3 and 5 are not possible. Info to point 2: Acrobat JavaScript can't create folders.
Copy link to clipboard
Copied
Point 3 :
app.execMenuItem("SaveAs");
Point 5 :
JavaScript can close the document but cannot quit Acrobat.
Copy link to clipboard
Copied
Hi JR_Boulay,
Can the app.execMenuItem("SaveAs"); function be inserted into the code to bring up the “Save As” box along with the predefined saving location and save name that I have coded above?
Cheers,
Seb.
Copy link to clipboard
Copied
No. It's essentially the same as clicking the Save As command under the File menu of the application.
Copy link to clipboard
Copied
So is there any way to bring up the Save As box AND pre fill the save name and save location?
Or is it a silent save as I have done in the above code OR what you describe with the app.execMenuItem("SaveAs"); which is essentially clicking the save as button in the menu? which wont pre fill the save name and location?
Copy link to clipboard
Copied
So is there any way to bring up the Save As box AND pre fill the save name and save location?
No.
Or is it a silent save as I have done in the above code OR what you describe with the app.execMenuItem("SaveAs"); which is essentially clicking the save as button in the menu? which wont pre fill the save name and location?
Yes, those are your only options.
Copy link to clipboard
Copied
Hmm well that's a bit annoying.. but ultimately good to confirm.. I'm going to use a work around to point 4 by making each file name unique by including a time stamp (date and time fields). YYYYMMDDHHMM or something like that.
Copy link to clipboard
Copied
For saving I use a script that displays an alert box containing the new unique name before displaying the Save As dialog box.
So, the end user can copy-paste the new unique name from the alert box to the Save As dialog box.
Here is a sample, you just have to adjust the "strFixe" var (line 2), the "Name" field name (line 3), and the "Date" field name (line 4):
/******************************************************/
var strFixe = "Note-de-frais";
var strNom = this.getField("NOM").value;
var strNum = this.getField("DATE").value
/* language detection */
if (app.language == "FRA") {
var strTitre = strFixe + " - Enregistrement";
var strQuestion = "COPIEZ le nom propos\u00E9 ci-dessous et COLLEZ le dans la fen\u00EAtre suivante pour l'utiliser comme nom de fichier :";
} else {
var strTitre = strFixe + " - Save As";
var strQuestion = "COPY below proposed text and PASTE it in the following box to use it as file name:";
}
/* new file name concatenation */
var strDisplay = strNum + "_" + strNom + "_" + strFixe;
/* alert box */
var saveRep = app.response({cQuestion: strQuestion, cTitle: strTitre, cDefault: strDisplay,});
if (saveRep != null) {
/* Acrobat Pro detection */
if (app.viewerVariation == "Full") {
/* edit the document Title */
this.info.Title = strNum + " - " + strNom + " - " + strFixe;
}
/* hide the target button and save */
event.target.display = display.hidden; // optional
app.execMenuItem("SaveAs");
}
/******************************************************/
Copy link to clipboard
Copied
Hi JR,
Quick question I tried this on DC Pro and it worked! yay
I tried it on a different PC with Adobe Reader DC and it doesn't work as intended. I can copy the text but as soon as I click Ok it wipes what I have saved from my clipboard..
Any thoughts?
Cheers,
Seb.
Copy link to clipboard
Copied
Here is an article on the topic: https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript
Copy link to clipboard
Copied
No, hélas.
I never got this issue.
Copy link to clipboard
Copied
FYI for those interested I used the following:
Trusted Level Function
saved in Notepad under the Adobe / Javascript folder
mySaveAs = app.trustPropagatorFunction(function(doc,path) {
app.beginPriv();
doc.saveAs(path);
app.endPriv();
})
myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) {
// Privileged and/or non-privileged code above
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
// Privileged and/or non-privileged code below
});
PDF Button
Code under button that is executed on Mouse up click
// build file name
var myFileName = getField("SAP_Work_Order").value + " - " + getField("Form_Name").value + " - " + getField("Todays_Date").value + ".pdf";
// add folder name
myFileName = "/c/Offline Forms/" + myFileName
myTrustedSpecialTaskFunc(this, myFileName);
app.alert("This Form (" + getField("SAP_Work_Order").value + " - " + getField("Form_Name").value + " - " + getField("Todays_Date").value + ") has saved successfully to the following location: /C/Offline Forms/" , 3);
Further Explanations
The "Todays_Date" field has the following:
The above code allowed me to fill most of my requirements to a point that I was happy with:
Copy link to clipboard
Copied
I don't think anyone pointed this out to you, but the "app.trustPropagatorFunction" function doesn't do anything. You don't need it. You have one nested function too many.
Copy link to clipboard
Copied
Then what will be the better script for trusted level function. Thanks
Copy link to clipboard
Copied
Look at myTrustedSpecialTaskFunc
Copy link to clipboard
Copied
Please explain what you want to do on a new post.
Copy link to clipboard
Copied
I would like to create a JS that will save the PDF document creating a specific folder as well as naming that folder and inserting the PDF in there. The name of the folder and the file will be pulled from information populated within the form. Thanks
Copy link to clipboard
Copied
Not possible. Acrobat JS can't create folders.
Copy link to clipboard
Copied
Acrobat JavaScript can't create folders.
Copy link to clipboard
Copied
How about just saving the file name with the forms contents. Once the file name is created then they can just copy and past and create a folder and then insert the file within that. Thanks
Copy link to clipboard
Copied
Yes, that's possible, but it would require installing a script on the local computer of each user. See earlier replies in this thread for more details.
Copy link to clipboard
Copied
How do i go about creating a JS Script for users don't understand that part next thing is it's a Shared PDF on Microsoft Cloud but they can save to there local computer. ALso what's Trusted Level Function. THanks
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks so much try67 i'll look into all of this shortly.