These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Save file button with date&time stamp

cyfu
Registered: Apr 26 2011
Posts: 32
Answered

Hi all,
I have the following code in the folder level as a trusted function:
 
//DateTime function
function myDateString()
{
 
return util.printd("yyyymmdd_HHMMss", new Date());
 
}
 
// SaveAs Function
var mySaveDoc = app.trustedFunction(function(oDoc,cPath,cF1Name)
{
 
app.beginPriv();
var myPath = app.getPath(cPath, cFlName) + myDateString() + ".pdf";
 
// saveAs is the only privileged code that needs to be enclosed
// with beginPriv/endPriv
odoc.saveAs(myPath);
app.endPriv();
 
});
 
In my Save button, I have the following Javascript:
 
// First make sure the function exists
if(typeof(mySaveDoc) == "function") {
var sPath = this.path; // get path including file name and type
// save this doc, in sPath
mySaveAs(this, "/g/busunits/", this.documentFileName);
app.alert({cMsg:"File successfully archived!\n\n" + "Ready for QA Compliance signature. File can be closed.", nIcon:3});
} else {
app.alert("Missing Save Function\n" +
"Please contact forms administrator");
}
// end button mouse up action
 
It's saving to the G: folder with the name of the file but the date/timestamp is not being added onto the end. Could someone provide some guidance?

My Product Information:
Acrobat Pro 7.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
At what point are you calling the myDateString function to set the value of the field for the date stamp.

George Kaiser

cyfu
Registered: Apr 26 2011
Posts: 32
Ok, modified the folder level script to the following:

//DateTime function
function myDateString()
{

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

}

// SaveAs Function
var mySaveDoc = app.trustedFunction(function(oDoc)
{
if (aDocumentFileName == "Application Form-Main.pdf")
{
app.beginPriv();
var myPath = "G:/BusUnits/" + myDateString() + " - " + Part1 + " - " + Part2 + " - " + ".pdf";

// saveAs is the only privileged code that needs to be enclosed
// with beginPriv/endPriv
oDoc.saveAs(myPath);
app.endPriv();
}
});

and my button script to the following:

DisableFormField("SB2")
Part1 = resolveNode("Application Form-Main.pdf.Page1.23").rawValue;
Part2 = resolveNode("Application Form-Main.pdf.Page1.26").rawValue;

event.target.mySaveDoc(event.target);

Nothing is happening besides the save button (SB2) being read only. Now its not saving anymore. The myDateString() is being called as part of the whole function at the oDoc.saveAs(myPath) statement right?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
You're using LiveCycle code in an Acrobat form.
resolveNode and rawValue do not exist in this environment.
You need to use getField and value instead.
Also, it seems like you're passing the field to mySaveDoc, but then try to use it as a Document object.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

cyfu
Registered: Apr 26 2011
Posts: 32
Yea, finally realized what I was doing wrong from another forum topic, thanks for the reply.

Another question for capitalizing the first letter of a word based on one of your code.
Document level script below:
function specialCaseStateCode(str) {
if (/^[a-zA-Z]{2}$/.test(str))
str = str.toUpperCase();
return str;
}
Field (format custom keystroke script):
var words = event.value.split(" ");
for (i=0; i < words.length; i++) {
words[i] = specialCaseStateCode(words[i]);
}
event.value = words.join(" ");

Have the exact code in the form, but doesn't seem to work. Able to point me in the right direction?
a1retouching
Registered: Aug 4 2011
Posts: 1
Hi guys,

I'm so happy I found this discussion.

I am currently struggling very very hard trying to do exactly the same.
This is the very first time that a >potential< client is asking to have a file saved with date/time stamp attached to the filename.On here I found
"How to save a PDF with Acrobat JavaScript"
and it talks about this in parts I think...

Also "Using Trusted Functions" and "Entering Folder Level Scripts"
but it's just too much for me to understand and follow - one thing that does not help me too much really is that English is not my main language...

Sounds like "cyfu" has this figured out and knows what to do to make this work.

I am really asking for help.
Some sort of step-by-step walk-through would be awesome.

THANK YOU SO MUCH!!!!
Martin