Skip to main content
Hasan KOYUNCU
Inspiring
November 16, 2018
Answered

Save FDF as a silently and using name from Acrobat form field.

  • November 16, 2018
  • 6 replies
  • 1977 views

Dear All;
I would like to save the donation receipt information as a FDF, which is I already created through Acrobat Pro DC version 2019.008.20080 fillable form.

Again, through the code I found on this forum site, I can save the PDF form as a complete. But I want to save as a FDF, how to change the JavaScript code for this purpose?

Thanks in advance for your help

Code:@ !

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

  }

  }

);

This script for the button in Acrobat Form.

var directory = "/Users/hasankoyuncu/Desktop/untitled folder/"

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

  mySaveAs(this, directory, this.getField("BenefactorName").value + " " + this.getField("NameOfCharity").value + " " + this.getField("DonationDate").value + ".pdf");

} else {

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

}

My system is:

MacBook Pro (Retina, 15-inch, Mid 2014)

This topic has been closed for replies.
Correct answer try67

You need to use the exportAsFDF method instead of saveAs.

Edit: fixed a small typo in the method name...

6 replies

Hasan KOYUNCU
Inspiring
November 16, 2018

Dear Mr. try67​​

Thank you so much. You are awesome!

Legend
November 16, 2018

Ah, I see part of the problem.

In the documentation you will see that doc.exportAsFDF has multiple parameters. So when you call

exportAsFDF ( thepathnameyouwant )

it isn't treated as  a pathname. You need to use

exportAsFDF ( { keyname : thepathnameyouwant } )

where keyname is the name of the key that identifies the path.

Hasan KOYUNCU
Inspiring
November 16, 2018

I'm not very experienced for JavaScript. This form for a donation, thank you very much if you explain more.

try67
Community Expert
Community Expert
November 16, 2018

Change this line:

oDoc.exportAsFDF(cPath + cFlName);

To:

oDoc.exportAsFDF({cPath: cPath + cFlName});

Legend
November 16, 2018

It's no good telling us just that you change the code. What do you change the code to? Did you observe, too, that it is not "ExportAsFDF" but "exportAsFDF"?

Hasan KOYUNCU
Inspiring
November 16, 2018

Yes, I made a capital letter by mistake. Now it saves as a FDF but without using the updated field name.

try67
Community Expert
Community Expert
November 16, 2018

Again, you need to post your code... We can't help you without knowing the details of what you're doing.

Legend
November 16, 2018

Yes, we understand that. You need to use exportAnFDF and perhaps create a myExportFDF function. Which part of this is giving you the problems? Please don't just as us to code it for you, our aim is to help you learn to solve your own problems.

Hasan KOYUNCU
Inspiring
November 16, 2018

Thank you so much. I appreciated.

Legend
November 16, 2018

You couldn't find a way to export an FDF with the exportAsFDF method? Please show the code you tried and tell us how it failed. (Note the spelling error: it's exportAsFDF not exportAnFDF).

Hasan KOYUNCU
Inspiring
November 16, 2018

I am using below code for save as a PDF. But I would like to save as FDF with this method.

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

  }

  }

);

This script for the button in Acrobat Form.

var directory = "/Users/hasankoyuncu/Desktop/untitled folder/"

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

  mySaveAs(this, directory, this.getField("BenefactorName").value + " " + this.getField("NameOfCharity").value + " " + this.getField("DonationDate").value + ".pdf");

} else {

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

}

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 16, 2018

You need to use the exportAsFDF method instead of saveAs.

Edit: fixed a small typo in the method name...

Hasan KOYUNCU
Inspiring
November 16, 2018

Sirtry67​​​;

I don't have enough knowledge of JavaScript. Please Can you type some of the sample code.

Legend
November 16, 2018

Please take look at the JavaSxript reference and let us know if it’s not clear.