Copy link to clipboard
Copied
I'm looking for help and suggestions for a problem I've been struggling with. I've built a set of PDF forms with a button that executes javascript code using the saveAs function. The script renames the pdf file and saves it to a different folder (which I retrieve from a persistent global variable). This script is working reliably. This is a windows environment and my users are accessing the pdf's using Acrobat Reader. I've set up trusted Windows folder paths to make this work.
The issue is that once this script is executed and the file renamed and saved, if I apply an electronic signature and attempt to save to the same filename (i.e., as assigned and saved by the script) it fails and won't save the file, issuing an error that "function parameter had incorrect value".
I've pursued various approaches to resolve this. I considered developing a white list file to modify policy rules. However, when reviewing the Protected Mode log file, there are so many errors and policy issues logged that it seemed impractical to figure out what policy rules to place in a white list to resolve this. For now I have staff following a relatively simple procedure where they close the file after running the saveAs script, then reopen the file (from the recent files list), and then apply the electronic signature. This normally works fine, but if they have multiple pdf files open, this sometimes issues an "access denied" error, at which point they have to close Acrobat Reader entirely, then reopen the file, then it works.
I've attempted various other configuration changes with Acrobat Reader, but with no luck. So, any suggestions or javascript methods I might try so that the saveAs script doesn't prevent the signature from being applied and the file saved with the same name (as generated and saved by the script) would be greately appreciated.
Copy link to clipboard
Copied
This continues to frustrate me, and am hoping some constructive suggestions can be shared.
I've been pursuing different options, but no luck so far. Since closing and reopening the file through the UI seems to work, I've attempted to add that to my javascript. However, I can't get it to work. It will close the document, and it can reopen the original file (i.e., the file that was originally opened before the saveAs, but it won't reopen the pdf file. I've attempted this with a folder level script thinking that I potentially needed to be at folder level in order to reopen the file. But, I can't get it to work and reopen the file. It doesn't produce an error, it just does nothing I can see.
I've also attempted to create a folder level script to apply the digital signature. I'm using the signatureSign method, placed in a trustedFunction, but just get a NotAllowedError when I attempt to execute it. So, this is a deadend so far as well.
Am still hoping someone might have useful suggestions on this.
Copy link to clipboard
Copied
Can you share the file, or at least your full code?
Copy link to clipboard
Copied
I'll share both the document level code that is use to rename/save files, and the folder level code I've been experimenting with to apply a digitial signature.
My document level code to rename/save is working the way I'd like, except for then preventing me from applying a signature and saving to the same file name (whether through the UI or javascript). Here it is:
var WinGPath = global.IntStorPath;
var GFName = this.getField("Text13").value.trim() + " (Intake)" + ".pdf";
var CAPath = this.path;
var WinCPath = "";
var aPathComps = CAPath.split("/");
var CFName = aPathComps[aPathComps.length-1];
if (aPathComps[1].length == 1)
{
WinCPath = aPathComps[1] + ":\\";
}
else
{
WinCPath = "\\" + "\\" + aPathComps[1] + "\\";
}
for (var i = 2; i < aPathComps.length-1; i++) {WinCPath = WinCPath + aPathComps[i] + "\\"; };
if ((this.getField("Text13").value == "") || (this.getField("Text12").value == ""))
{
app.alert("Both Client Name & Intake are required--File not Saved!", 3);
}
else
{
if (WinGPath == "")
{
app.alert("Standard Folder missing--File not Saved!", 3);
}
else
{
if (CFName.toLowerCase() == GFName.toLowerCase())
{
try
{
this.saveAs(WinCPath + CFName);
app.alert("File Saved with original name/location." + "\r\n" + "(" + WinCPath + CFName + ")", 3);
}
catch (err)
{app.alert("Save cancelled by User!" + "\r\n" + "(Note, if not user cancelled, perform Menu-based Save As and then restart Acrobat.)", 3); }
}
else
{
var FExist = true;
try {app.openDoc(WinGPath + GFName); FExist = true; }
catch (err) {FExist = false;}
if (FExist)
{
app.alert("Dup file risk; file not saved; confirm file name & location; perform menu-based SaveAs if appropriate.", 3);
this.fileToClose = app.openDoc(WinGPath + GFName);
this.fileToClose.closeDoc(true);
}
else
{
try
{
this.saveAs(WinGPath + GFName);
app.alert("New file saved in standard location." + "\r\n" + "(" + WinGPath + GFName + ").", 3);
}
catch (err)
{app.alert("Save cancelled by User!" + "\r\n" + "(Note, if not user cancelled, perform Menu-based Save As and then restart Acrobat.)", 3); }
}
}
}
} Here's the folder level scipt I've been experimenting with to apply the signature, but am getting a NowAllowedError. If I could get this to work, of course my problems would be solved, in fact, it'd be preferable to having users go through the steps to apply their signature and re-save the file through the UI. On the script below, I've tried just typing in the file/path and field information directly into the "var Trusted_Sign ..." statement, i.e., to test if the variables aren't getting passed properly, but it still isn't working.
var Trusted_Sign = app.trustedFunction(function(FileSP, f){app.beginPriv(); var ppklite = security.getHandler("Adobe.PPKLite"); ppklite.login("<password>", "/C/Users/name/AppData/Roaming/Adobe/Acrobat/DC/Security/Name.pfx"); var myInfo = {password: '<password>', location: 'Office', reason: 'completing form', contactInfo: 'name@gmail.com', appearance: 'basic', mdp: 'allowNone'}; f.signatureSign({oSig: ppklite, oInfo: myInfo, cDIPath: FileSP, bUI: true}); app.endPriv(); });
app.addMenuItem({cName: "Doc Sign", cParent: "Help", cExec:"var FileSP = this.path; var f = this.getField('Signature2'); Trusted_Sign(FileSP, f); "});
Copy link to clipboard
Copied
You have to use saveAs from a trusted context, just like you did with the signatureSign method.
Copy link to clipboard
Copied
I'll give that a try and see if it resolves the issue where it prevents me from applying the signature. I figured that if the saveAs was working, which it is, that I was in the clear.
Copy link to clipboard
Copied
Tried this and it didn't resolve the issue of the saveAs script preventing me from applying a digital signature and then saving to the same file name. Specifically, I set up a trustedFunction saveAs script as a folder level script. It worked fine to rename the file and save it to the path I store as a global variable. However, once I do that, I can't then sign and save the document. I first have to close the document and reopen it.
Here's the folder level script I tested for this:
var Trusted_MyDocSave = app.trustedFunction(function(oDoc, PParm){app.beginPriv(); oDoc.saveAs(global.IntStorPath + PParm); app.endPriv(); });
app.addMenuItem({cName:"TestSave", cParent:"Help", cExec:"var FV = this.getField('Text13').value + ' (Intake).pdf'; Trusted_MyDocSave(this, FV); "});
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more