These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Saving file to a generic(token) path possible

cyfu
Registered: Apr 26 2011
Posts: 32
Answered

Instead of hardcoding the filepath to save the pdf to, I'm trying to setup the code that saves to a temporary location. So that it would goto any user saving the form to a temp directory.
 
Example: %tmp% = c:\DOCUME~1\any_user\LOCALS~1\Temp?
 
Currenty trusted function:
var mySaveAs = app.trustedFunction(
function(oDoc,cPath,cFlName)
{
app.beginPriv();
// Ensure path has trailing "/"
cPath = cPath.replace(/([^\/])$/, "$1/");
try{
oDoc.saveAs(cPath + cFlName);
}catch(e){
app.alert("Error During Save");
}
app.endPriv();
});
 
Currently using this script in a button
 
// mouse up action script to call the trusted mySaveAs function
// First make sure the function exists
if(typeof(mySaveAs) == "function") {
var sPath = this.path; // get path including file name and type
var aPath = sPath.split('/'); // make array to remove the file name and type
aPath[aPath.length - 1] = ''; // remove the file name and extension
sPath = aPath.join('/'); // rebuild path without file name and extension
// save this doc, in sPath, with the name of 'MyNewPDF.pdf'
mySaveAs(this, "/%tmp%/", + "In Progress" + "-" + "TEMP" + ".pdf");
} else {
app.alert("Missing Save Function\n" +
"Please contact forms administrator");
}
// end button mouse up action
 
Getting error during save.

My Product Information:
Acrobat Pro 7.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I don't think you can use this kind of folder notation ("%tmp%") in Acrobat.
You need to specify the actual path.
Also, it will be helpful if you say which exact error message you're getting since it contains a lot of useful like the type of error and the line where the error occurred.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Look up the "app.getPath()" function in the Acrobat JavaScript Reference.

Also read these articles:
http://acrobatusers.com/tutorials/file-paths-acrobat-javascript
http://acrobatusers.com/tutorials/2006/string_splitting
http://www.pdfscripting.com/public/department47.cfm?sd=35

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

cyfu
Registered: Apr 26 2011
Posts: 32
Accepted Answer
Thanks again Thom for your guidance and help as that worked.

Now, what I'm trying to do is to put this save script into the Digital Signature properties (this script executes when the field is signed). Essentially suppressing the Sign and Save As and Sign and Save Dialog that automatically appears.

I found one of your previous post with the following code that I wrapped into a folder level function:

function SigSave()
{
var oSigHdlr = security.getHandler( "Adobe.PPKLite" );oSigHdlr.login( cPwd,cPathtoSigFile); // Setup Signing Properties
fld = this.getField("35");fld.signatureSetSeedValue({legalAttestations:["What, me worry?"],reasons:["For the heck of it"]});
//Apply Signature and save back to original file
var bRtn = fld.signatureSign({oSig:oSigHdlr, bUI:false, oInfo:{password:cPwd}});
}

I tried adding this into the script executes when signed:

this.getField("35").value = SigSave(event.value);

but the dialog still shows up.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Signature handling is a privileged operation. I'm pretty sure that particular script cannot be run inside a document context. Acrobat is allowing the script to proceed with the signing process, but its displaying the UI because the execution context is not trusted.

This kind of script (i.e., one dealing with security operations) is very likely to operate differently in different versions of Acrobat. A lot has changed since Acrobat 7. You should test your code on Acrobat 9 and Acrobat X.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

cyfu
Registered: Apr 26 2011
Posts: 32
For now I'm stuck with acrobat 7 pro as my company isn't ready to deploy the later versions.
I did put the code in a folder level context, but calling it from the document action level within the digital signature field properties.

Are you saying even the document level actions need to be ran from the folder level?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Only the function that performs the signing needs to be in a folder level trusted function. The function can be called from anywhere.

Read this article:
http://acrobatusers.com/tutorials/2008/10/using_trusted_functions

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

cyfu
Registered: Apr 26 2011
Posts: 32
I think one of the problems is that we're using Entrust PKI plugin for digital signatures.

I changed the security.getHandler parameters in the folder level script:
//Get and login to security handler
var oSigHdlr = security.getHandler( "Entrust.PPKEF" );oSigHdlr.login(cPwd,cPathtoSigFile); // Setup Signing Properties
fld = this.getField("35");fld.signatureSetSeedValue({legalAttestations:["What, me worry?"],reasons:["For the heck of it"]});
//Apply Signature and save back to original file
var bRtn = fld.signatureSign({oSig:oSigHdlr, bUI:false, oInfo:{password:cPwd}});

Still having trouble tying to just sign and save silently.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
My impression (from previous experimentation with this code) is that the UI is displayed when a parameter is missing or the execution context does not have sufficient trust.

The cDIPath parameters is not required, the file should save back to the original file name, but try including it anyway, and anything else that might be necessary.

Also, does your folder level trusted function include the app.beginPriv() and app.endPriv() calls?


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script