简体   繁体   中英

Adobe DC - Save As using JavaScript

This is my first attempt at using Javascript...

I am attempting to create a Save As button on a form that will:

  • Create a file name based on fields;
  • Save to a specific folder (And if it doesn't exist then create folder);
  • Bring up the "Save As" box for confirmation (as opposed to a silent save);
  • Bring up a warning IF Adobe is going to save over an existing pdf (aka has the exact same name);
  • Close Adobe after all of the above is executed.

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.


The code I have so far is:

Trusted Level Function saved in a Notepad.js file 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() ;

Unfortunately, in Acrobat JavaScript, if you give the saveAs method a path that doesn't exist, the call will fail; it can't create directories. You can't even set a default directory for it to save to, you need to give it the full path to the new PDF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM