Skip navigation
Currently Being Moderated

Dynamic date stamp along edge of page

Jan 7, 2010 3:21 PM

I have a javascript to put a dynamic date stamp vertically along the left edge of a PDF.  This script works fine for the first page.  However, on a multi-page document the date stamp is not rotated 90 degrees, so from the 2nd page on, there are just a few letters horizontally.  Here is the script.


var inch = 72;

for (var p = 0; p < this.numPages; p++) {

    // create rectangle quads for field

    var aRect = this.getPageBox( {nPage: p} );

    aRect[0] = 0.0;

    aRect[1] = 0.0;

    aRect[2] = 26.0;

    aRect[3] = 792;

    // now construct text field to fill with date information

    var f = this.addField("PrintField", "text", p, aRect )

    f.delay = true;

    f.rotation = 90;

    f.textSize = 16;

    f.textFont = font.HelvB;

    f.textColor =;

    f.alignment = "center";

    f.readonly = true;

    f.print = true;

    f.hidden = true;

    f.delay = false;


// Adds a doc level script to populate text field when doc prints from

// Acrobat or the free Adobe Reader. Note: the '\r' character represents a

// carriage return.

var myWillPrintScript = 'var f = this.getField("PrintField"); \r' + 'f.hidden = false; \r' + 'var d = new Date(); \r' + 'var year = d.getYear()+1900; \r' + 'var mins = d.getMinutes(); \r' + 'if (mins < 10) { \r' + '    mins = "0" + mins}; \r'  + 'if (d.getHours() >= 12) { \r'  + 'mins = mins + " PM"; \r'  + '} else { \r'  + 'mins = mins + " AM"; } \r'  + 'f.value = "THIS DOCUMENT ONLY EFFECTIVE ON " + (d.getMonth()+1) + "/" + d.getDate() + "/" + year; \r'

var myDidPrintScript = 'var f = this.getField("PrintField"); \r'

                           + 'f.value = ""; \r'

                           + 'f.hidden = true; \r'

// Now set the scripts to execute on the Will/Did Print events.

this.setAction("WillPrint", myWillPrintScript);

this.setAction("DidPrint", myDidPrintScript);

FYI: This script came from the following other threads and links stampstoPDFswhenprinting


Can anyone figure out why this script is not working on all pages?





  • Currently Being Moderated
    Jan 8, 2010 1:43 AM   in reply to HardDriver2

    It sounds like the pages are rotated.

    There's an example in the reference files how to rotate fields so that they

    match the page rotation. I think it's one of the addLink examples.

    Mark as:
  • Currently Being Moderated
    Jan 13, 2010 8:54 AM   in reply to HardDriver2

    This is a bug of Adobe Acrobat. Add the following code after your for loop:

    for (var p = 0; p < this.numPages; p++) {

        var f = this.getField("PrintField." + p);

        f.rotation = 90;
    Mark as:
  • Currently Being Moderated
    Apr 18, 2012 11:17 PM   in reply to HardDriver2

    Does anybody know why the text rotation is applied on a separate pass, rather than when the field is established intitally? I've been testing 'rotation' and it appears to rotate the text in a field on only the first page to which it is applied.  The remaining pages all have horizontal text (0 degree rotation) in a vertical text box, which is not what is wanted.


    -- Roy Zider

    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 1:34 AM   in reply to FUBARinSFO

    I don't see a reason why not to include it in the first loop.

    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 12:07 PM   in reply to Gilad D (try67)

    I didn't either.  But in a similar piece of my test code, the .rotation property (or method?) did not work after the first page.  I had to name each text box on each page with a unique name, and then it worked within a single loop. 


    If you note, the text field 'PrintField' is not renamed in the first loop.  In the second, it is 'PrintField.'+p with getfield.  so maybe the first loop names the text field on each page uniquely automatically, not explicitly.


    Wasn't able to find anything about this anomaly anywhere.


    -- Roy Zider

    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 12:22 PM   in reply to FUBARinSFO

    The rotation property is unique for each widget, that's why it requires a loop that accesses each widget individually (using the period and number after the field's name). I would suggest changing the first loop so that each field has a unique name, something like "PrintField_"+p .

    Otherwise, just leave it the way that it is since it seems to be working.


    Edit: it shouldn't actually work that way, but as was mentioned above, it seems to be a bug.

    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 12:41 PM   in reply to Gilad D (try67)

    I checked the API reference, and the code snippet does indeed show the unique field naming for each page.  But no mention anywhere of why this should be so. 


    Thanks for the confirmation. 


    -- Roy Zider

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points