Skip to main content
garys32397767
Participating Frequently
July 2, 2018
Answered

JavaScript SaveAS from form field help please.

  • July 2, 2018
  • 3 replies
  • 4632 views

I have read through multiple pages here and used various codes but am having no luck.  The most common error I receive is a cPath unsupported error.  I have place code in the trusted folder script area.  I have tried various button codes but same results.

let me explain my unique situation and what I need to accomplish and maybe there is a simpler way.  all I need is to have a for button simple enough.  it needs when pressed by the user to either silently save as or bring up a dialog, preferably a dialogue that will save the filled pdf as a new name chosen from 2 or three form fields that have been filled out by the user with valid either number or letter characters.  honestly it could even save the form as the same name but to a new folder named from just one form field and i would be able to live with that.

this will be used on only one pc on a closed network and the form will be saved to a local path.  I understand I may still need trusted script which is fine but also that information may not apply since this is only on one pc and all local cant I just have a button script and I am using adobe acrobat pro dc and have the enhanced security settings set to trust the folder??

Any help would be greatly appreciated

something like this for my button script??

this.saveAs("/c/MyDocs/" + getField("Customername")).value;

but this returns unsupported cPath error:

UnsupportedValueError: Value is unsupported. ===> Parameter cPath.

Doc.saveAs:1:AcroForm:Save:Annot1:MouseUp:Action1

This topic has been closed for replies.
Correct answer try67

Your code is incorrect. It should be:

this.saveAs("/c/MyDocs/" + getField("Customername").value);

Also, does the value of the field end with ".pdf"? If not, it will fail.

3 replies

garys32397767
Participating Frequently
July 2, 2018

Is it further possible to have this script also create a folder based on form field value?  as it is setup currently it saves to a pre defined folder.  could i add something like:

this.saveAs("/c/Users/GaryLeePC/Documents/getField("Customername").value" + getField("Customername").value + ".pdf");

this is an example and I know this doesn't work but is something similar possible or am I pushing my luck?

garys32397767
Participating Frequently
July 2, 2018

Update:

I gave changed code to:

this.saveAs("/c/Users/GaryLeePC/Documents/" + getField("Customername").value + "/" + getField("Customername").value + ".pdf");

trying to achieve having it create a folder and receive the error:

RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.

Doc.saveAs:1:AcroForm:Save:Annot1:MouseUp:Action1

===> The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.

try67
Community Expert
Community Expert
July 2, 2018

No, a script can't create a folder.

Bernd Alheit
Community Expert
Community Expert
July 2, 2018

What do you use in the trusted function?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 2, 2018

Your code is incorrect. It should be:

this.saveAs("/c/MyDocs/" + getField("Customername").value);

Also, does the value of the field end with ".pdf"? If not, it will fail.

garys32397767
Participating Frequently
July 2, 2018

ok, so I changed it to ths:

this.saveAs("/c/MyDocs/" + getField("Customername").value + ".pdf" );

so it should be adding .pdf correct?  but i receive the same error.

try67
Community Expert
Community Expert
July 2, 2018

Where did you place this code, exactly? Are you sure it's the exact same

error message?