Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Sep 24, 2024 Sep 24, 2024

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.

 

TOPICS
Create PDFs , JavaScript , PDF , PDF forms
666
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Sep 25, 2024 Sep 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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2024 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 25, 2024 Sep 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!

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2024 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 25, 2024 Sep 25, 2024

a) Thank you for the clarification!

b) Perfect!

c) Did you get a different test result? I cannot get Reader to respect my "bPromptToOverwrite:false". Is it a Reader or Windows setting?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2024 Sep 25, 2024

It worked for me.  I'm not sure why it doesn't respect the setting.  What is your function script and what is the call?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 25, 2024 Sep 25, 2024

hmm : /

my trusted function:

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

 

my call:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2024 Sep 25, 2024

Are you saying it's popping up the Save As window?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 26, 2024 Sep 26, 2024

No, not a Save As - dialog/window, but a promt to confirm write/overwrite rights. Like this:

this.PNGexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

Reader and Acrobat JavaScript folders have separate locations.  Are you sure the correct file is in the Reader JS folder and Reader has been restarted?  Other than that, I'm not sure.  You could try without bPromptToOverwrite and bCopy because they are optional parameters and the defaults are false.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 26, 2024 Sep 26, 2024
LATEST

Yes, I made sure the same config.js is in both folders. The thing is bCopy works perfectly and I explicitly looked up the bPromptToOverwrite-option since the mentioned write permission popped up as a default. Bummer. Anyways, thx for all the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines