• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Save As button in pdf form, to save in the same folder, based on field values.

New Here ,
Jul 13, 2019 Jul 13, 2019

Copy link to clipboard

Copied

Hello guys!

I tried finding a solution for this over the past 2 weeks, but I didn't come to a reasonable conclusion.

Let me describe what I have and what I need to do: I have a pdf form which gets filled by the staff at my office and I need a button to save (silently if needed) the file based on different text field values (numbers and letters), in the same folder as the original form. It would be nice to flatten everything before so people won't tamper with what was filled, but that is another discussion.

This being said, during research on the forums, I saw that the saving function of pdf's is not straightforward (meets the purpose of pdf, of course) and I need 2 things:

- a script which I would place in the folder that I use and/or in the install directory of Adobe Acrobat

- the script that goes in the button itself.

I already saw that people have tackled various varieties of this issue (either same folder or field based save as), but not both at the same time. I tried putting together some code, but to no avail. My humble request would be to help me with the following:

1) where exactly do I need to place the .js file that would make the things work? Does it need to be called in a specific way? What should go in that code exactly? I found this variant to start with:

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

  }

  }

);

2) what is the code that could do the required job? I found the following, but I couldn't make it work. I am not proficient in coding, so a little help would help

// determine the directory path for the current document

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

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

  mySaveAs(this, directory, this.getField("Field1").value + " " + this.getField("Field2").value + " " + this.getField("Field3").value + ".pdf");

} else {

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

}

Thank you very much, your help would be vastly appreciated. I have access to Adobe Acrobat Pro XI and Acrobat Pro DC if there's any difference between them.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

363

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2019 Jul 13, 2019

Copy link to clipboard

Copied

1) Put the file in the Javascript folder of Adobe Acrobat installation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2019 Jul 14, 2019

Copy link to clipboard

Copied

LATEST

The code itself seems fine to me. If you installed the first part into a

.js file in the JavaScripts folder, what is the result when you use it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines