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

Interactive buttons running Javascript to save to specific file location not working

Guest
Dec 14, 2017 Dec 14, 2017

Hi,

I have a PDF form with 2 buttons at the top that are set to run a Javascript. One of them saves the file to a specific server location under a certain file name. The other saves it in the same way and also sends an email with the form as an attachment.

In previous versions of this form, both buttons worked perfectly fine. I have changed a number of things now about the form itself but no changes were made to the buttons. However, the save function of the buttons no longer work (though the second button still generates an email fine).

I've run through every line of Javascript code and confirmed it's the same as the previous version, so I don't think it's the code. I feel like it's a setting on the doc itself, but as far as I can see, they're all the same as well. Any ideas what else (settings or anything else) might block the save function on the buttons from working?

Thanks in advance!

TOPICS
Acrobat SDK and JavaScript
684
Translate
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 ,
Dec 15, 2017 Dec 15, 2017

Are there any error messages? Can you post the code you're using?

On 15 December 2017 at 04:51, hollys45933388 <forums_noreply@adobe.com>

Translate
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
Guest
Dec 15, 2017 Dec 15, 2017

There are no error messages. It doesn't do anything at all. This is the code I am using for the save button.

function myDateString(){

return util.printd("mmddyyyy", new Date()); }

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

  } 

  } 

); 

// determine the directory path for the current document

var directory = "/s/Server/completed forms"

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

  mySaveAs(this, directory, this.getField("LegalName").value + "_" + this.getField("Interviewer").value + "_"+ myDateString() + ".pdf");

} else {

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

}

Another thing, I have this doc in a folder on a shared server, and that folder is locked for editing except by me. It's a different folder than the save path in the code (the template is in /s/Server/templates but the button is supposed to save the file to /s/Server/completed forms). Could that somehow be affecting it?

Thanks

Translate
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
LEGEND ,
Dec 15, 2017 Dec 15, 2017

All JavaScripts that are run in Acrobat/Reader need to be within the PDF or in one of 2 very specific folders on the user's system. They cannot be anywhere else.

Translate
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
Guest
Dec 15, 2017 Dec 15, 2017

Could you please explain that further? I'm a bit confused.

I'm talking about the saved location of the actual PDF file. The Javascript code I included above is from a button in the PDF.

Translate
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 ,
Dec 15, 2017 Dec 15, 2017

That's exactly the problem. The trusted function needs to be located in .js file that is saved into the JavaScripts folder of the application.

Read this tutorial: https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts

Translate
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
LEGEND ,
Dec 15, 2017 Dec 15, 2017
LATEST

Your button calls a function and the code for that function must be either in the open PDF, or in the  Acrobat/Reader program folder or in the Acrobat/Reader user's folder. The code cannot be located anywhere else. You can use app.getPath() method to locate those files.

For any code using the privileged mode the code using that feature must reside in either the Acrboat/Reader JavaScript folder in applications program  folder or the user's application folder for Acrobat/Reader.

Try this code in your JavaScript console:

   console.println("Program: " + app.getPath("app", "javascript"));

  try {

      var userBatch = app.getPath("user","javascript");

   } catch(e) {

      var userBatch = "User has not defined any custom batch sequences";

   }

   console.println("User" + userBatch);

Result:

Program: /C/Program Files (x86)/Adobe/Acrobat DC/Acrobat/JavaScripts

User/C/Users/geprgel/AppData/Roaming/Adobe/Acrobat/Privileged/DC/JavaScripts

Translate
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