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

Create Automatic "Save As" Date and Time Button

gbollinger
Registered: Dec 12 2008
Posts: 10

Hello All,

Have created a "Save" button on my PDF that will allow user to save the file to a specific location on their drive. Although I have it the way I want it there is one need thing. I need the output file to read UTC time instead of the local PC time.

Here is my code:

//DateTime function
function myDateString()
{

return util.printd("dddd mmmm dd yyyy HHMM", new Date());

}

// SaveAs Function
var mySaveDoc = app.trustedFunction(function(doc) {

app.beginPriv();
var myPath ="c:/Documents and Settings/FRAC/" + myDateString() + ".pdf";

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

});

Note: The script above is place in the Adobe Reader folder on the local drive.

The script below script is in attached to the button in the PDF doc itself:

event.target.mySaveDoc(event.target);

When I open the pdf doc and click the “Save” button it saves it to “myPath” above with the correct date/time stamp of the local PC.

i.e. “Saturday December 13 2008 1600”

I need it to save the time as UTC instead of local.

i.e. “Saturday December 13 2008 2100” (Corrected for UTC)

Any help is greatly appreciated

PS: Is there a way to incorporate this js into the document itself? This in order to keep the end user from installing the js into the local reader js floder

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Since you are using JavaScirpt, why not use the "getUTC" methods for date, year, month and day?

//DateTime function
function myDateString() {
// zero bases array of days of the week
var aDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");
// zero based array of the months of the year
var aMonths = new Array("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November", "December");

var oNow = new Date(); // get the current date object
// build the date time string using the UTC value
var sUTCDateTime = aDays[oNow.getUTCDay()]; // place the day of the week string
sUTCDateTime = sUTCDateTime + " " + aMonths[oNow.getUTCMonth()]; // add month string
sUTCDateTime = sUTCDateTime + " " + oNow.getUTCDate(); // add day of month
sUTCDateTime = sUTCDateTime + " " + oNow.getUTCFullYear(); // add full year
sUTCDateTime = sUTCDateTime + " " + oNow.getUTCHours(); // add hours
sUTCDateTime = sUTCDateTime + oNow.getUTCMinutes(); // add minutes

return sUTCDateTime; // return formatted string
}

George Kaiser

gbollinger
Registered: Dec 12 2008
Posts: 10
Works great!! Thank you very Much You Are A Great Help!!

One Thing...

When the UTC time hits 0000 the time appears as 000.

ie. If the actual time is Tuesday December 16 2008 0010.
It would return as Tuesday December 16 2008 010.


How would I fix this?

g
John Grand
Registered: Aug 18 2009
Posts: 18
I am very new to understanding the coding using Livecycle. I have a need to save a copy of my form when exiting to my c:\temp directory. The file needs to be renamed with the current date and time. I expirimented with some of the examples posted but no luck. I tried the button example. Where does the main body of code get placed. I would love to have a sample form that does this so I could learn from it. Thanks John