Have you ever needed to submit a PDF to a specific file path, but couldn’t figure out how to accomplish this? Let’s do it!
Here’s how the file name will appear when the users selects the submit button in the form in this scenario.
Here’s the JavaScript placed on the submit button in the PDF:
if(typeof(mySaveAs) == "function"){ mySaveAs(this,this.path); app.alert("Your file has been submitted.\n" + "\Please close this document.", 2, 0, "Success"); }else{ app.alert("Missing Save Function\n" + "\nPlease contact forms administrator", 1, 0, "Error"); }
Here’s the Folder Level JavaScript saved as mySaveAs.js:
var getLoginName = app.trustedFunction( function () { //Get and return the user's login name app.beginPriv(); return identity.loginName; app.EndPriv(); }); var mySaveAs = app.trustedFunction(function() { //Create AlphaNumeric String for Filename function myIdString(){ var text = ""; var possible = "0123456789"; for (var i = 0; i < 8; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } //Create Date and Time function myDateString(){ return util.printd("m-d-yyyy h-MM-ss tt", new Date()).toUpperCase();; } //Create Filename var myFileName = getLoginName() + "–" + myIdString() + "-" + myDateString(); //Save the File app.beginPriv(); this.saveAs("/F/Test/" + myFileName + ".pdf"); app.endPriv(); });
In order to perform a SaveAs function that actually writes the file, a Folder Level script is necessary to be placed in a specific file location on the PC for the PDF to reference. To do this, it is important to note, you will need administrative access to all PC’s of which will be using the PDF form. The above script was placed in the below locations for the PDF to reference upon the users clicking the submit button.
Path for users using Adobe Acrobat Reader DC to fill out and submit this form:
C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Javascripts
Path for users using Adobe Acrobat DC to fill out and submit this form:
C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
If you do not have administrator access to the directories necessary to place the Folder Level JavaScript file, here’s an alternative file location you may use to test functionality.
C:\Users\YOUR USERNAME\AppData\Roaming\Adobe\Acrobat\Privileged\DC\Javascripts
Note: you will have to view hidden files, as well as create the “Privileged” folder and contents identically there after.
Update: On Apple Macintosh, the application JavaScript folder is in the configuration file inside the Acrobat Application Package.