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

adding a date field in 9 pro but reading in 9 reader

s010341
Registered: May 14 2010
Posts: 5

I have added the following code in acrobat 9 javascript folder to add a filed named xftDate:

app.addSubMenu({ cName: "Footer",cUser: "Set/Remove Footer", cParent: "File", nPos: 20 });

app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Footer", cExec: "SetFooter(1)"});

app.addMenuItem({ cName: "-------------------------------", cParent: "Footer",cExec: "{}"});

app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Footer", cExec: "RemoveFooter(1)"});

var inch = 72;
for (var p = 0; p < this.numPages; p++) {
var aRect = this.getPageBox( {nPage: p} );
aRect[0] += .25*inch; // position rectangle (.5 inch, .5 inch)
aRect[2] = aRect[0]+5.5*inch; // from upper left hand corner of page.
aRect[1] -= .25*inch; // Make it .5 inch wide
aRect[3] = aRect[1] - 35; // and 24 points high
function SetFooter(ARG)
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;
var AcDate = new Date();
for (var p = 0; p < this.numPages; p++)

{

if (ARG==1 || ARG==3) {var fd = this.addField("xftDate", "text", p, aRect )};

fd.textSize=6; fd.value = util.printd("yyyy/mmm/dd, HH:MM", AcDate) + " (" + FileNM +")"; }

if (ARG==2 || ARG==3){var fp = this.addField(String("xftPage"+p+1), "text", p, [350,15,300,30]);

fp.textSize=6; fp.value = "Page: " + String(p+1)+ "/" + this.numPages; }

} }

function RemoveFooter(ARG)
{

if (ARG==1 || ARG==3) {var x = this.removeField("xftDate");}

if (ARG==2 || ARG==3) {for (var p = 0; p < this.numPages; p++)

{

var x = this.removeField(String("xftPage"+p+1)); }

} }

***I have added this code in the javascript folder in reader 9 hoping to fill the xftDate field created in PRO 9 but I am getting the following error:
this.getField is not a function
1:Folder-Level:App:Document.js

var fld = this.getField("xftDate"); fld.textFont = font.HelvB;
var d = new Date();
var t = new Date();
fld.value = ("Destroy 24 hrs. after print date: " + util.printd("mm/dd/yyyy ", d) + util.printd("hh:MM tt", t));

My Product Information:
Acrobat Pro 9.3.1, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Exactly when are you getting this error with Reader?

Upon starting Reader?
Opening a PDf in Reader?

I would have placed the code you placed in the Reader JavaScript folder in the 'Will Print' action of the PDF you added the 'xftDate' field to. You can add more code to your button to add the code to your button and use the 'setAction' method to set the 'WillPint' trigger.

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't place "this" references to a document in a folder-level script. That will not work in Acrobat, nor in Reader.
A folder-level script is launched when the application is opened, BEFORE any file is opened, so "this" will not refer to a document object at that time.

You need to place the entire first block of code, from
var inch = 72;
to
aRect[3] = aRect[1] - 35; // and 24 points high
within the function that uses it, ie SetFooter.

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

s010341
Registered: May 14 2010
Posts: 5
I am getting the error when I start Reader. It makes sense since no PDF is open at the time. I am trying to automatically get the field added when I create it in PRO and filled with current date when the document is opened in Reader, since Reader will not allow me to addField. I will try the Will Print option.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The process is:

1. Create the field using Acrobat.
2. Add a will print action in Acrobat to PDF to fill in the date just prior to printing.
3. Save the form.

Since the field has been added to the PDF you do not need to add the field in Reader. Since the will print action is present in the PDF, that action will place the information into the field before the PDF is sent to the printer in either Acrobat or Reader. There is no need for any action needed by the user's copy of Acrobat or Reader.

See [url=http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=25008]Batched Time and Date stamp when printing?[/url] for links to additional post about using the batch process to add the field and will print actions.

George Kaiser

s010341
Registered: May 14 2010
Posts: 5
Having problems with the printing of the "date" field in Reader. These are the codes I have in the javascript folder in Pro. The field does create in Pro and when brought up in Reader the Field shows on screen but when it prints no date prints on the paper. What am I doing wrong?

// this adds the file option to create the field "date". I also have a seperate Will Print script(listed below) to fill in the field when it is printed from Reader.This field is blank when created, the colored field does show up on document. The document is then saved.

app.addSubMenu({ cName: "Footer",cUser: "Set/Remove Footer", cParent: "File", nPos: 20 });

app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Footer", cExec: "SetFooter(1)"});

app.addMenuItem({ cName: "-------------------------------", cParent: "Footer",cExec: "{}"});

app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Footer", cExec: "RemoveFooter(1)"});


function SetFooter(ARG)
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;
var AcDate = new Date();
var inch = 72;
for (var p = 0; p < this.numPages; p++){

if (ARG==1) {
var aRect = this.getPageBox( {nPage: p} );
aRect[0] += .25*inch; // position rectangle (.5 inch, .5 inch)
aRect[2] = aRect[0]+5.5*inch; // from upper left hand corner of page.
aRect[1] -= .25*inch; // Make it .5 inch wide
aRect[3] = aRect[1] - 35; // and 24 points high


var fd = this.addField("date", "text", p, aRect );

fd.textFont=font.HelvB;
var d = new Date();
var t = new Date();
fd.value = (""); }


} }

function RemoveFooter(ARG)
{

if (ARG==1 || ARG==3) {var x = this.removeField("date");}

if (ARG==2 || ARG==3) {for (var p = 0; p < this.numPages; p++){

var x = this.removeField(String("xftPage"+p+1)); }

} }

**this is a seperate js in the javascript folder in Pro
// add WillPrint script to populate the form field

this.setAction({cTrigger: "WillPrint", cScript: "var fd = this.getField("date");
fd.value = ("Destroy 24 hrs. after print date: " + util.printd("mm/dd/yyyy ", d) + util.printd("hh:MM tt", t)) });
s010341
Registered: May 14 2010
Posts: 5
Having problems with the printing of the "date" field in Reader. These are the codes I have in the javascript folder in Pro. The field does create in Pro and when brought up in Reader the Field shows on screen but when it prints no date prints on the paper. What am I doing wrong?

// this adds the file option to create the field "date". I also have a seperate Will Print script(listed below) to fill in the field when it is printed from Reader.This field is blank when created, the colored field does show up on document. The document is then saved.

app.addSubMenu({ cName: "Footer",cUser: "Set/Remove Footer", cParent: "File", nPos: 20 });

app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Footer", cExec: "SetFooter(1)"});

app.addMenuItem({ cName: "-------------------------------", cParent: "Footer",cExec: "{}"});

app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Footer", cExec: "RemoveFooter(1)"});


function SetFooter(ARG)
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;
var AcDate = new Date();
var inch = 72;
for (var p = 0; p < this.numPages; p++){

if (ARG==1) {
var aRect = this.getPageBox( {nPage: p} );
aRect[0] += .25*inch; // position rectangle (.5 inch, .5 inch)
aRect[2] = aRect[0]+5.5*inch; // from upper left hand corner of page.
aRect[1] -= .25*inch; // Make it .5 inch wide
aRect[3] = aRect[1] - 35; // and 24 points high


var fd = this.addField("date", "text", p, aRect );

fd.textFont=font.HelvB;
var d = new Date();
var t = new Date();
fd.value = (""); }


} }

function RemoveFooter(ARG)
{

if (ARG==1 || ARG==3) {var x = this.removeField("date");}

if (ARG==2 || ARG==3) {for (var p = 0; p < this.numPages; p++){

var x = this.removeField(String("xftPage"+p+1)); }

} }

**this is a seperate js in the javascript folder in Pro
// add WillPrint script to populate the form field

this.setAction({cTrigger: "WillPrint", cScript: "var fd = this.getField("date");
fd.value = ("Destroy 24 hrs. after print date: " + util.printd("mm/dd/yyyy ", d) + util.printd("hh:MM tt", t)) });
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you checked the Acrobat JavaScript console for any errors?

Do you understand how to place a quoted string within a quoted string?

In Acrobat pro have you checked to see if the 'Will Print' document event field has the required JavaScript?

Your code:
Quote:
fd.value = ("Destroy 24 hrs. after print date: " + util.printd("mm/dd/yyyy ", d) + util.printd("hh:MM tt", t)) });
My code from [url=http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=21777]Batch process to add Java Script to Will Print[/url]
Quote:
// Add WillPrint script
// set the text for the willPrint JS script action
var myWillPrintScript = 'var sPrintText = \"Printed on \" + util.printd(\"mmm dd, yyyy\", new Date()) + \" at \" + util.printd(\"HH:MM\",new Date());\\n'
myWillPrintScript += 'this.addWatermarkFromText({cText: sPrintText, nFontSize: 12, bOnScreen: false, bOnPrint: true, nTextAlign: 2, nHorizAlign: 2, nVertAlign: 0, nHorizValue: -52, nVertValue: +375 });\\n'
// set the WillPrint action
this.setAction({cTrigger: "WillSave", cScript: myWillPrintScript});
Note the use of the backward slash, '\', being uses as an escape charater befor the double quote within a string variable delimited by double quotes.

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You are still making the same mistake I pointed earlier.
You can't use the "this" object in a folder-level script (unless it's in a function) to point to a document.

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

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You should use the 'cExec' optional parameter to add a script that would make this menu item available only when a document is open.

George Kaiser