Copy link to clipboard
Copied
Hi Guys and Gals (assuming there are some Nerdy Gals out there )
I have this lovely expense claim form I created and want to have it approved electronically, meaning I will fill out the form and click a "Submit" button to email it to my boss for approval. This all works fine.
When my boss gets the email in Outlook, he double-clicks the attached expense form to review. Hopefully he will click "Approve" at the bottom
The "Approve" button tries to save the Form using this.saveAs in a privileged context.to a trusted location on the bosses hard disk.
That's where it all goes wrong....
Anyway here's my code:
In C:\Program Files (x86)\Adobe\Reader 11.0\Reader\Javascripts I have a script called MyTrusted.js:
var MySavesAs=app.trustedFunction(
function(oDoc,cPath,cFlName)
{
cPath=cPath.replace(/([^/])$/,"$1/");
try{
oDoc.saveAs(cPath+cFlName);
}catch(e){
app.alert("Error during save");
}
}
)
I'm sure Thom Parker will recognise this, cos he wrote it!
In the mouseUp JavaScript for my button, I have
if (typeof(MySaveAs)=="function")
{
var MyPath="C:/AIF/";
var MyFileName=this.documentFileName;
MySaveAs(this,MyPath,MyFileName);
}
Anyway. When the boss opens the attached pdf in Outlook, it is cached in C:\outlookcache\
When he hits the Approve button with the aforementioned button script, he gets "Error during save" from the trusted function MySaveAs.
I have tried to add the directory C:\outlookcache\ to the list of Privileged Locations under the Enhanced Security Preferences, Reader doesn't accept this.
If the Boss manually Clicks File>Save As and saves to C:\AIF\ (which IS on the list of Privileged Locations), and then opens that file from that location he can approve without problems i.e. the script works perfectly.
So, how do I get around this security restriction?
"Enable Protected Mode at Startup" has been switched off, as has "Enable Enhanced Security" but to no avail
Please tell me I am doing something wrong!!
Louis
Copy link to clipboard
Copied
Your path is wrong. Acrobat uses device independent paths that are different than your normal windows paths. Try this instead:
"/C/AIF/"
Copy link to clipboard
Copied
Nope that didn't work
As I said, this script does work if the file has been opened from a "Privileged Location", but not as an attachment to an Email
Copy link to clipboard
Copied
Using the following code:
var ReportedPath=this.path;
app.alert("the PATH is: "+ReportedPath);
I get this:
Copy link to clipboard
Copied
Which version of Outlook, and on what operating system are you running this?
What is the exact error,that is getting thrown? You can display that by changing this one line:
app.alert("Error during save: " + e);
Copy link to clipboard
Copied
Outlook Version 14.0.7166.5000
Windows 7 Enterprise SP1
Error During SAve: NotAllowedError: Security settings prevent access to this property or method""
Copy link to clipboard
Copied
What is the file-name you're trying to use?
Copy link to clipboard
Copied
it varies with job number and date. Here's an example:
RKB - 10012345 - OKeeffe - 12-Apr-2016.pdf
No illegal characters
Like I said, this works fine from another directory. There doesn't seem to be a problem with the path or filename
Copy link to clipboard
Copied
You need to wrap the call to Doc.saveAs() with app.beginPriv() and app.endPriv():
var mySaveAs = app.trustedFunction(
function(oDoc,cPath,cFlName)
{
// Ensure path has trailing "/"
cPath = cPath.replace(/([^/])$/, "$1/");
try{
app.beginPriv(); // <-- NEW
oDoc.saveAs(cPath + cFlName);
app.endPriv(); // <-- NEW
}catch(e){
app.alert("Error During Save: " + e);
}
}
);
You can find more about how to raise the execution privileges in the API documentation: Acrobat DC SDK Documentation
Find more inspiration, events, and resources on the new Adobe Community
Explore Now