Hi All
im trying to create a saveAs function for a form I have created. I want to take away as much of thought process away from the users as the simple saveas got them all confused bless!!!
So what im trying to achieve, is a save button that saves the form to a specified location with a unique name and then sends an email to another person who then has to sign of the form the email part I think I can achieve its the saveAs and the trusted function aspect that i cannot get my head around im not a java programmer the script below script seemed to work but came back with a message:
NotAllowedError: Security settings prevent access to this property or method.
Doc.saveAs:52:AcroForm:Button 1:Annot1:MouseUp:Action1
function DoesFileExists(pathname)
{
var result = false;
try
{
var otherDoc = app.openDoc(pathname);
if (otherDoc != null)
{
result = true;
otherDoc.closeDoc();
}
}
catch(e)
{
result = false;
}
return result;
}
// create a unique filename for output file
function GetUniqueOutputFileName(pathName)
{
var i = 1;
var baseName = pathName.slice(0, pathName.length - 4);
var testName = pathName;
while (DoesFileExists(testName) == true)
{
testName = baseName + " " + i + ".pdf";
i++;
}
return testName;
}
var i = this.path.search(/[^:/]+\.pdf$/);
var fname = this.path.slice(i, this.path.length - 4);
// replace /c/data/ with a desired folder path where to store extracted files
var folder = "/m/testpdf/";
// now add time stamp data to the filename
var t = new Date();
fname += " - " + t.toLocaleString();
var outputname = fname.replace(/[,\\/\?*<>]/g," ");
outputname = outputname.replace(/[:]/g,"-");
var outputpath = folder + outputname + ".pdf";
this.saveAs(GetUniqueOutputFileName(outputpath));
So I added what I think is a trusted function from article on here but now im getting a syntax error no formal parameters
// trusted saveAs Function
var saveAs = app.trustedFunction(
function(this.saveAs(GetUniqueOutputFileName(outputpath))
{
app.beginPriv();
this.saveAs(GetUniqueOutputFileName(outputpath));
app.endPriv();
}
);
You have to explicitly pass that reference, together with the path.
Also, there are various other things that are wrong with your trusted function. Use this code instead:
trustedSaveAs = app.trustedFunction(function(doc, path) {
app.beginPriv();
doc.saveAs(path);
app.endPriv();
});
You can then call it like this:
trustedSaveAs(this,"/c/temp/1.pdf");
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com