Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

Community Beginner ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

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.

TOPICS
JavaScript

Views

38

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Aug 30, 2021 Aug 30, 2021
Change this part of the code: this.documentFileName + myDateString()+ ".pdf" To: this.documentFileName.replace(".pdf", myDateString() + ".pdf")

Likes

Translate

Translate
Adobe Community Professional ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

Change this part of the code:

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

To:

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

Likes

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 Beginner ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

Dear @try67 ;

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

Likes

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 Beginner ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

LATEST

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

}

Likes

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