Skip to main content
Participating Frequently
September 24, 2024
Answered

Force/prompt overwrite via this.saveAs - function not working

  • September 24, 2024
  • 1 reply
  • 1154 views

Hi everyone,

I use the “simple” version of this.saveAs with (this, this.path) without any problems. However, when I use the “extended” version with ({cPath:path, bPromptToOverwrite:true, bCopy:true}) to force/block overwriting or create copies accordingly, nothing happens and the debugger gives the following error:

NotAllowedError: Sicherheitseinstellungen verhindern den Zugriff auf diese Eigenschaft oder Methode.
(NotAllowedError: Security settings prevent access to this property or method)


Here is my entry at folder level:

mySaveAs = app.trustPropagatorFunction(
function(doc,path)
{
app.beginPriv();
doc.saveAs(path);
app.endPriv();
})

mySaveAsFunc = app.trustedFunction(function(doc,path)
{
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
});


and here my button-script

var indipath = this.getField("path");
var addName = this.getField("Vname").valueAsString + ".pdf";
myFileName = indipath.valueAsString + addName;
this.saveAs({cPath:myFileName, bPromptToOverwrite:true, bCopy:true});
///this works perfectly:

///mySaveAsFunc(this, myFileName);

 

Do I have to include the this.saveAs({...}) expression somehow in the trusted function first?

 

Any kind of information is welcome. Many thanks in advance.

 

This topic has been closed for replies.
Correct answer PDF Automation Station

a)   oDoc and doc are both variables.  They can be any legitimate variable (doc usually represents a document, oDoc usually represents a document as well "object Document").   Again, any legitimate variable can be used (myDoc, otherDoc, Doc1, Doc2).  You are passing the document object object through the function.

b)  Absolutely, and you should so you only need one function.  Here's an example of the function:

mySaveAsFunc = app.trustedFunction(function(doc,pth,oWrite)
{
app.beginPriv();
oDoc.saveAs({cPath:pth, bPromptToOverwrite:oWrite, bCopy:true});
app.endPriv();
});

You would call it like this:

mySaveAsFunc(this,pth, true);//or like this:
mySaveAsFunc(this,pth, false);

You can do the same thing with the bCopy paramater.  Simply define the variables in the parentheses of the functon, then define them when you call it (keeping the same order in the parenthesis of the call).

c) It shouldn't be ignored.  Let me test.

1 reply

PDF Automation Station
Community Expert
Community Expert
September 24, 2024

this.saveAs is privileged so it must be in a trusted function.  The button must call the function, not this.saveAs directly.  Use the following trusted function:

 

mySaveAsFunc = app.trustedFunction(function(doc,pth)
{
app.beginPriv();
oDoc.saveAs({cPath:pth, bPromptToOverwrite:true, bCopy:true});
app.endPriv();
});

 

And call it in the button like this:

 

var indipath = this.getField("path");
var addName = this.getField("Vname").valueAsString + ".pdf";
var pth = indipath.valueAsString + addName;
mySaveAsFunc(this,pth);

 

I change path to pth.  You shouldn't use path as a variable since it is already defined in DOM JavaScript.

jvd369Author
Participating Frequently
September 25, 2024

Thanks alot Station! This was the much needed hint.

Still 3 things:

a) In the trusted function I had to change the defining parameter to "oDoc, pth" (instead of doc, pth) or should I change oDoc within the function to "doc". What is the difference between doc and oDoc?

b) Is there a way to leave the overwrite and copy parameter in the trusted function variable? Right now I just have 4 different trusted functions with the appropriate values to call individually - just an optimization thing, I guess?

c) When working in Reader, the promt will appear ignoring my "bPromptToOverwrite:false" - is this avoidable?

 

Thx again!

 

PDF Automation Station
Community Expert
Community Expert
September 25, 2024

a)   oDoc and doc are both variables.  They can be any legitimate variable (doc usually represents a document, oDoc usually represents a document as well "object Document").   Again, any legitimate variable can be used (myDoc, otherDoc, Doc1, Doc2).  You are passing the document object object through the function.

b)  Absolutely, and you should so you only need one function.  Here's an example of the function:

mySaveAsFunc = app.trustedFunction(function(doc,pth,oWrite)
{
app.beginPriv();
oDoc.saveAs({cPath:pth, bPromptToOverwrite:oWrite, bCopy:true});
app.endPriv();
});

You would call it like this:

mySaveAsFunc(this,pth, true);//or like this:
mySaveAsFunc(this,pth, false);

You can do the same thing with the bCopy paramater.  Simply define the variables in the parentheses of the functon, then define them when you call it (keeping the same order in the parenthesis of the call).

c) It shouldn't be ignored.  Let me test.