Skip to main content
Hasan KOYUNCU
Inspiring
August 30, 2021
Answered

How to silently saving Acrobat form file by adding datetime combination to existing filename.

  • August 30, 2021
  • 1 reply
  • 888 views

Hello to everyone;
When after filling the dynamic acrobat form and silently save the which is entered data in a separate folder so far everything is fine.
This data file gets its name from the serial number field.
For example: PR-345675.fdf
But how to save it silently in a different folder with the current filename+date+time combination after that flatten the form completely.
Because I want to keep the main dynamic form layout file be safe.
I want a result like this.
For example: PR-345675_300821_022956.pdf
I do all this with the Acrobat JavaScript code which is assigned to


Code for Folder Level

MySaveAs.js (for silently save)

var mySaveAs = app.trustedFunction(

  function(oDoc, cPath, cFlName) {

  // Ensure path has trailing "/"

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

  try {

  app.beginPriv();

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

  app.endPriv();

  } catch (e) {

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

  }

  }

);

Config.js (For date time)

//DateTime function
function myDateString() {

return util.printd("ddmmyy_HHMMss", new Date());

}

Code for Clickable Button

1) Save fdf

var directory = "/Users/koyuncu/Documents/Charity-fdf/"

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

  myExportFDF(this, directory, this.getField("SerialNumber").value + ".fdf");

} else {

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

}

2) Save pdf (Fully Flatten Form)

for (var i=0; i<this.numFields; i++) {
    var f = this.getField(this.getNthFieldName(i));
    if (f==null) continue;
    f.readonly = true;
}
this.removeField("Print");
this.removeField("Clear");
this.flattenPages()

var directory = "/Users/koyuncu/Documents/Charity/"

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

  mySaveAs(this, directory, this.documentFileName + myDateString()+ ".pdf");

} else {

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

}

But I have small issue:
File name became like that: PR-345675.pdf300821_022956.pdf.
I don't want the extension ".pdf" repeated twice here in the final filename.

Thank you in advance for your help.

This topic has been closed for replies.
Correct answer try67

Change this part of the code:

this.documentFileName + myDateString()+ ".pdf"

To:

this.documentFileName.replace(".pdf", myDateString() + ".pdf")

1 reply

try67
try67Correct answer
Community Expert
August 30, 2021

Change this part of the code:

this.documentFileName + myDateString()+ ".pdf"

To:

this.documentFileName.replace(".pdf", myDateString() + ".pdf")

Hasan KOYUNCU
Inspiring
August 31, 2021

Dear @try67 ;

First of all, thank you very much for your quick reply.
You are excellent in Acrobat form.
Thanks

Hasan KOYUNCU
Inspiring
August 31, 2021

This is Updated Code

for (var i=0; i<this.numFields; i++) {
    var f = this.getField(this.getNthFieldName(i));
    if (f==null) continue;
    f.readonly = true;
}
this.removeField("Button4");
this.removeField("Clear");
this.flattenPages()

var directory = "/Users/koyuncu/Documents/Charity/"

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

  mySaveAs(this, directory, this.documentFileName.replace(".pdf", myDateString() + ".pdf"));

} else {

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

}