Skip to main content
Underz
Inspiring
May 29, 2015
Answered

Save PDF File Name as Field Name in PDF

  • May 29, 2015
  • 5 replies
  • 50798 views

Hi all,

I've read through this thread : https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript ‌ and I still can't figure this out.

I want to have a custom save button on my fillable form PDF, and have it save the file name with the fields in my form.  The field names are "RequestedBy" , "NameofEvent" , "EventStartmdyy"

so as an example, the pdf is filled out and returned to me with its default pdf name as "Event Request Form Update-1.pdf" , then I get it, and click the button, then it saves it as "DarinVegasTradeshowJune152015.pdf" and saves to a specific folder every time.

I read about getting trusted access and put it into a javascript either in the folder or on my computer? My co-worker and I will be the only person to save these, so it's only on two machines.

Hope you can assist.

Thank you

This topic has been closed for replies.
Correct answer Underz

Follow my instructions above to get the correct syntax for the folder name.


I tried the following;

The correct syntax I got, based on the debugger for "this.path" returned

/HAUCACAM0007VS/Shares/Marketing_bridge/Darin/`MasterTracker/EventRequestForms/1/test.pdf

so I changed the code from this

// determine the directory path for the current document 

var directory = this.path.substring(0, this.path.lastIndexOf('/') +1); 

to this

// determine the directory path for the current document 

var directory = "/HAUCACAM0007VS/Shares/Marketing_bridge/Darin/`MasterTracker/EventRequestForms/1/"

and it worked.  I swear I tried that, and a few variations before. 

Very interesting.  I can send myself this PDF, open it without saving, click the save and it points to my directory I wanted.

Yay! Solved!

Thank you try67!

Again, for the sake of people googling how to do this...

---------------------------

I pasted this code into a text file, saved it as a javascript (.js file), in the following locations Program Files > Adobe > Acrobat > Javascript, I also pasted it into the folder where I will be saving the file.

  1. var mySaveAs = app.trustedFunction(
  2.   function(oDoc, cPath, cFlName) {
  3.   // Ensure path has trailing "/"
  4.   cPath = cPath.replace(/([^/])$/, "$1/");
  5.   try {
  6.   app.beginPriv();
  7.   oDoc.saveAs(cPath + cFlName);
  8.   app.endPriv();
  9.   } catch (e) {
  10.   app.alert("Error During Save - " + e);
  11.   }
  12.   }
  13. );

Then, I created a button, added a javascript to it.  the "this.getField's are looking for field names in my PDF, "RequestedBy" is a field in my PDF that has my sales managers name, it then adds a space beside it (+ " " +), then goes to the next field I want.  so when I fill out the pdf, it then saves it as SalesManager EventName June 1 2015.pdf.

  1. // determine the directory path for the current document
  2. var directory = "/HAUCACAM0007VS/Shares/Marketing_bridge/Darin/`MasterTracker/EventRequestForms/1/"
  3. if (typeof(mySaveAs) == "function") {
  4.   mySaveAs(this, directory, this.getField("RequestedBy").value + " " + this.getField("NameofEvent").value + " " + this.getField("EventStartmdyy").value + ".pdf");
  5. } else {
  6.   app.alert("Missing Save Function. Please contact forms administrator ");
  7. }

Hope that helps anyone else looking to do this, it's fairly easy once you know where to save the javascripts (and what to put in it), then edit another javascript code to meet your needs.

Thank you!

5 replies

tomr27467065
Participant
March 10, 2021

I am attempting to do the same thing.  I see that this thread is from 2015.  Do the same rules still apply?

 

I need a javascript that will extract 3 form fields (Name, District, Birthdate) from my pdf and rename it, then place it as an attachment in an email with that file name (name_district_birthdate). Then, I need it to email it to specific individuals. Is this possible?

 

Thank you for your assistance.

Participant
September 2, 2016

Hi everyone,

I've created my pdf form and kept the file on Dropbox.

When i open the file and edit it, it saves on my dropbox with a new name. The SAVE button works perfectly on Windows.

However, when i try to edit the file on an Ipad or Android, the save button don't work?

Can anyone please help?

Thank you in advance!!

Participating Frequently
February 11, 2016

I am currently trying to achieve the same result.  I used the script below in my Javascript folder:

var mySaveAs = app.trustedFunction(

  function(oDoc, cPath, cFlName) {

  // Ensure path has trailing "/"

  cPath = cPath.replace(/([^/])$/, "$1/");

  try {

  app.beginPriv();

  oDoc.saveAs(cPath + cFlName);

  app.endPriv();

  } catch (e) {

  app.alert("Error During Save - " + e);

  }

  }

);

I then used this script for the button in LiveCycle:

var directory = "/c/temp/"

if (typeof(mySaveAs) == "function") {

  mySaveAs(this, directory, this.getField("UNID").value + ".pdf");

} else {

  app.alert("Missing Save Function. Please contact forms administrator ");

}

Nothing seems to happen.  I don't get the error message telling me to contact the adminstrator and the file won't save to my temp folder on the c drive.  Any ideas whats going on here?

try67
Community Expert
Community Expert
February 11, 2016

You can't use scripts written for Acrobat files on LCD files. The objects, properties and methods are very different in both environments.

For questions about LCD files try the LCD forum: LiveCycle Designer

Participating Frequently
February 12, 2016

Thanks!  I switched the button javascript from LCD to Acrobat which worked as I thought.  My next task is try to figure out how to save a multipage document to different directories when the button is clicked.  Any ideas where to start looking for that?

Underz
UnderzAuthor
Inspiring
November 19, 2015

Ok this is not working anymore, my company upgraded to adobe acrobat 11, and now my error says "Missing Save Function, Please contact forms administrator"

any idea to get this working again? nothing changed except new program.

I put the javascript into the new adobe 11 javascript folder also.

thx all

Karl Heinz  Kremer
Community Expert
Community Expert
November 19, 2015

The error message suggests that the function defined in the folder level script is not known, which means that the folder level script did either not execute, or that an error occurred while loading that script file and because of that, the execution of that script was stopped. Do you see any error messages in the JavaScript console? If not, make sure that your script is actually in the correct location. Take a look here for information about how to determine where a folder level script needs to be stored: https://acrobatusers.com/tutorials/print/entering-folder-level-scripts

Inspiring
November 19, 2015

After adding a folder level function requires a restart of Acrobat or Reader since the scripts in these files are only loaded into the memory used by Acrobat/Reader at the startup of the application and not updated as the contents of the folders are updated.

Karl Heinz  Kremer
Community Expert
Community Expert
May 29, 2015

The trusted function needs to be stored in a folder level script, so it needs to go either into the system level or the user level JavaScripts folder.

Underz
UnderzAuthor
Inspiring
May 29, 2015

Do you have an example of a trusted function? I am unaware of what that is, or looks like. Also, where would the system level default location be? Is the user level the 'folder' that the pdf is in?

I then also don't know how to code to suit my needs, maybe the trusted part made my test code not work? i am not sure.

thanks for your help

Underz
UnderzAuthor
Inspiring
June 1, 2015

You need to find out the internal path of that folder and then specify it as the second parameter for mySaveAs.

The best way to do that is to open a PDF file that's inside that folder, and then run this command in the JS console:

this.path

Then copy the first part of the output, until the file-name, and use it directly in your code.

It will probably be something like this:

/HA123/Shares/Marketing_bridge/Darin/`MasterTracker/EventRequestForms/


ok I've tried a bunch of things, and haven't got it to work. I tried pasting it in the javascript folder level, tried inside the code...nothing...

Where exactly do you paste that internal? I knew to switch the /'s ... but not sure exactly where. can you post an example of the code?

appreciate it