Skip to main content
Participant
Apr 6, 2018 2:25 PM UTC
Answered

Save PDF in Current Folder Named after Two Fields Javascript

Hello,

I have read through few discussions and can't seem to find a javascript that lets you save pdf in current folder. Everyone asks for it to be saved in a specified folder.
So, I was wondering if there is a javascript that can save the PDF in folder that the PDF is currently in named after two fields in Adobe Form.

Thanks!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Apr 6, 2018 3:15 PM UTC

Sure, that's possible.

You can use something like this to do it:

var newFileName = this.getField("Text1").valueAsString + "-" + this.getField("Text2").valueAsString + ".pdf;

this.saveAs(this.path.replace(this.documentFileName, newFileName);

4 replies

Participating Frequently
Dec 12, 2021 1:37 AM UTC

This is probably a case of the carpenter blaming his tools, but I wondered has anything changed in Adobe since this answer. 

When I run it I get "NotAllowedError: Security settings prevent access to this property or method...." in the console. In addition I have  copied other scripts dealing with saving  PDFs and have frequently gotten this message.

Stay safe

Thank you. 

Translate
Bernd Alheit
Community Expert
Community Expert
Dec 12, 2021 6:41 AM UTC

You need a trusted function. Read this:

https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript/ 

Translate
Participating Frequently
Dec 12, 2021 3:09 PM UTC

Mr. Alheit

Thank you. Thank you. Thank you. I can stop butting my head against a tree

 

I have build a program (ExpungeKY.com) where users (total strangers or their lawyers) can get a form, fill it out, save it and  later use it to expunge a criminal record. If I understand you correctly, there is no realistic way for me to have the file already be named, for example, "Jones-12345" when the user saves it. 

 

A person usually needs several different forms. My biggest number has been 40, but 6-10 is not unusual. I just thought it would help the user keep things straight if the files automatically came with a unique name. Of course the user can name the file the old fshioned way-- retype it. No big deal. Just a convenience.

 

I do a fair number of these forms myself. I assume there is a way to put this feature in a separate set of forms just for use only on my own cmputer. Is that a big deal?

 

Again thanks and stay safe. If you need to charge me to answer this, let me know. Jwp@aye.net.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Apr 6, 2018 3:15 PM UTC

Sure, that's possible.

You can use something like this to do it:

var newFileName = this.getField("Text1").valueAsString + "-" + this.getField("Text2").valueAsString + ".pdf;

this.saveAs(this.path.replace(this.documentFileName, newFileName);

Translate