Skip to main content
ytk1978
Known Participant
July 26, 2018
Answered

file name copied to text box in the form

  • July 26, 2018
  • 2 replies
  • 1938 views

is there way to automatically bring in file name in the one of the text box in the adobe form?

sorry in advance for dump question.

example for my question.  assume file name is: "john doe (XXXX) 07.26.2018.pdf"

take the john doe (name of the file) and automatically input in to one of the text box in the form.  text box name is "name"

Please let me know and thank you for your help.  THANK YOU!

This topic has been closed for replies.
Correct answer try67

You can use this code to do it:

this.getField("Name").value = this.documentFileName.split("(")[0];

this.getField("Date").value = this.documentFileName.split(") ")[1].replace(".pdf", "");

Place these two lines of code under Tools - JavaScript - Document JavaScripts in a new item called "Scripts".

2 replies

try67
Community Expert
Community Expert
July 26, 2018

Yes, it's possible to copy the file name to a specific field, but you seem to want to do something more complicated than that.

How would the script know which part of the name to copy? Should it copy the part before a "(" (if it always exists)? Something else?

ytk1978
ytk1978Author
Known Participant
July 27, 2018

Try67,  here is an example.

PDF file name is:   John Doe (1234) 07.26.2018.pdf.  there will always be file name like this.  when i open the file i want my pdf to brining the name and the date off of the PDF file name.

when i name or change or update the file name and open the file I want my pdf form to copy the file name into two text boxes.  two boxes names are:

1. "name"

2. "date"

on the "name" text box I want to bring in John Doe

and the "date" text box I want to bring in 07.26.2018 to the PDF form text box.

is this clear?  hope it helps and thank you very much for your help.

THANK YOU!

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

You can use this code to do it:

this.getField("Name").value = this.documentFileName.split("(")[0];

this.getField("Date").value = this.documentFileName.split(") ")[1].replace(".pdf", "");

Place these two lines of code under Tools - JavaScript - Document JavaScripts in a new item called "Scripts".

Thom Parker
Community Expert
Community Expert
July 26, 2018

Add this code to a document level script.

this.getField("FileNameField").value = this.documentFileName;

Of course you'll need to add a field to the form with the name "FileNameField", or change the name in the code to match the one on your form.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
ytk1978
ytk1978Author
Known Participant
July 27, 2018

what do you mean by document level script?  I am very new at this and i do not know much.

thank you for your help!

ytk1978
ytk1978Author
Known Participant
July 27, 2018

whenever there is change to file name or save as new file name and when file (PDF form) is open I want the data from file name to fill the two text boxes ("name" & date) in the PFD form. 

for example if the

file name is: John, Doe (1234) 07.26.2018.pdf

"Name" text box will get: John, Doe (1234)

and " Date Text box will get: 07.26.2018

if the file name is updated and/or changed to Doe, John (1234) 07.27.2018.pfd

"Name" text box will get: Doe, John (1234)

and " Date Text box will get: 07.27.2018

if this coding involves document level script please advise me how and where to do this well.

Thank you!