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

Saving File with JavaScript

New Here ,
Oct 22, 2019 Oct 22, 2019

Hello,

I have set up a PDF form which shall be stored under the name formed from the entries of two text fields via an implemented button. Saving the file works well now, but the user is not warned if a file with this name already exists.

I found several hints to a parameter called "bPromptToOverwrite", but unfotunately I can't get it included in the code of my script.
Does anyone know how to do it or what other possibility there could be?

Many thanks for any help!

2.5K
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 ,
Oct 22, 2019 Oct 22, 2019

You can do it by changing this line of your code:

doc.saveAs(path);

To this:

doc.saveAs({cPath: path, bPromptToOverwrite: true});

However, I would recommend you rename the path variable to something else, as there's already a property of the Document object with that name which can cause a conflict.

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 ,
Oct 22, 2019 Oct 22, 2019

You have a bigger issue than that. You can't define the trusted function inside your button. That won't work.

It has to be located in a privileged context, like a folder-level script. If you can't do that then the whole issue is moot, as you won't be able to save the file at all using a script.

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 ,
Oct 22, 2019 Oct 22, 2019

Hello try67,

thank you for your answer!

Saving the file worked without problems in the attached pdf-file. 

I hope, there will be a solution for the rest too, for example with browseForFile, bPromptToOverwrite or enabling "Menu Items JavaScript Execution Privileges option"....?

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 ,
Oct 22, 2019 Oct 22, 2019

It shouldn't work, unless you placed the file in a "trusted" folder or certified it.

If you don't do that you'll get this error message:

 

NotAllowedError: Security settings prevent access to this property or method.
App.trustPropagatorFunction:3:Field Speichern:Mouse Up

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 ,
Oct 22, 2019 Oct 22, 2019

Yes, I declared the folder as trusted in the Acrobat-security-settings...

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 ,
Oct 22, 2019 Oct 22, 2019

That explains it... If you're the only user of this form that's fine, but if you plan on sending it to others it's not going to work for them, unless they do the same.

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 ,
Oct 22, 2019 Oct 22, 2019

Yes, I know....The form will be used on only 2 PCs, but from several different persons. Therefore I,m concerned, that the one or other will not be as careful as he/she should. There should be an alert in any manner...

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 ,
Oct 22, 2019 Oct 22, 2019

You can do it by changing this line of your code:

doc.saveAs(path);

To this:

doc.saveAs({cPath: path, bPromptToOverwrite: true});

However, I would recommend you rename the path variable to something else, as there's already a property of the Document object with that name which can cause a conflict.

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 ,
Oct 22, 2019 Oct 22, 2019
LATEST

Hello try67,

you´re a hero!!

Works wonderful, exactly what I needed!

Thank you so much for your 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