Skip to main content
Participant
April 6, 2018
Answered

Save PDF in Current Folder Named after Two Fields Javascript

  • April 6, 2018
  • 2 replies
  • 1617 views

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 has been closed for replies.
Correct answer try67

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);

2 replies

Participating Frequently
December 12, 2021

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. 

Bernd Alheit
Community Expert
Community Expert
December 12, 2021
Participating Frequently
December 12, 2021

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 6, 2018

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);