Skip to main content
Participating Frequently
November 1, 2005
Question

Add current date to PDF documents

  • November 1, 2005
  • 127 replies
  • 43042 views
This doesn't seem like it should be hard, but I have been unable to find information on how to do it.

I have about 100 PDF files. Somewhere on them, I need to display "Date Printed: dd mmm yyyy", and have the current date displayed.

I don't care whether this is placed at the top of the page, the bottom, or opaque in the background.

I would like to be able to accomplish it using the batch command, but will perform manually if necessary.

I have Acrobat 7 Professional.

Can someone please help me out?
    This topic has been closed for replies.

    127 replies

    Bernd Alheit
    Community Expert
    Community Expert
    December 31, 2008
    For the correct use of the script you must add missing line breaks, e.g. for // and other code.
    Participating Frequently
    December 31, 2008
    I simply don't know where to add the missing "}" Line 21 is the last line of code, but I don't know what "compound statement 20" means. I randomly added two "}}" at the end of line 21, creating: ...this.addScript("AddMessage",strJS);}}
    and the error message disappeared. I could run the script, but no field with date was created in my test file. Can you help?
    Thank you.
    Bernd Alheit
    Community Expert
    Community Expert
    December 30, 2008
    Add the missing }
    Participating Frequently
    December 30, 2008
    I followed the instructions in Message #53 and pasted the code. I can't close the editor by selecting OK because it has an error: "missing } in compound statement 20: at line 21".
    Can someone tell me how to fix it?
    Thanks.
    Participating Frequently
    December 2, 2008
    Thanks Geo. With this revision the pdf its just like I was looking for.

    Very best Regards
    Inspiring
    December 1, 2008
    It appears you are trying something far beyond your programinging level.

    First I would change code so the fields are visible and fill in a value so I could see the results of my code:

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

    {

    var rCrop = this.getPageBox("Crop",i);

    if (rCrop[1] >= rCrop[2]) { // start of block of code for true

    var aRectangle = this.getPageBox( {nPage: i} );
    aRectangle[0] = aRectangle[2]-14;
    var fld = this.addField("ComboDatePrint", "text", i, aRectangle );
    var fld = this.getField("ComboDatePrint." + i);
    fld.alignment = "center";
    fld.textSize = 11;
    fld.textColor = color.black;
    fld.textFont = font.Times;
    fld.fillColor = color.white;
    fld.rotation = 270;
    fld.readonly = true;
    fld.print = true;
    fld.display = display.visible;

    console.println("Page: " + i + " Page Rotation: " + this.getPageRotation(i));

    } // end of true block
    else { // block of code for not >=

    var nRot = this.getPageRotation(i);
    var aRectangle = this.getPageBox( {nPage: i} );
    aRectangle[1] = aRectangle[3]+14;
    var fld = this.addField("ComboDatePrint", "text", i, aRectangle );
    var fld = this.getField("ComboDatePrint." + i);
    fld.alignment = "center";
    fld.textSize = 11;
    fld.textColor = color.black;
    fld.textFont = font.Times;
    fld.fillColor = color.white;
    fld.readonly = true;
    fld.print = true;

    fld.display = display.visible;

    console.println("Page: " + i + " Page Rotation: " + this.getPageRotation(i));
    } // end if else bocks

    } // end page loop

    this.getField("ComboDatePrint").value = "EXPIRATION. Vence: " + util.printd("dd/mm/yyyy h:MM:ss tt",new Date() )

    And then run the code from the JavaScript Debugging Console and observe the results.
    Participating Frequently
    December 1, 2008
    Hi dudes,

    I have tried several ways, with var nRot = this.getPageRotation(i); but I cant locate the text inside Box in vertical position on landscape pages, even though the box itself is in Vertical Position

    Any suggestions?

    Thank you very much
    Inspiring
    December 1, 2008
    JavaScript requires you block out the block of code to execute when there a multiple lines of code to be excuted and an 'if' statement does not end with a ';' if you want a line of code or block of code to be executed. You use the "{" and "}" brackets to mark the start and end of the code block.

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

    {

    var rCrop = this.getPageBox("Crop",this.pageNum);

    if (rCrop[1] >= rCrop[2]) { // start of block of code for true

    var aRectangle = this.getPageBox( {nPage: i} );

    aRectangle[0] = aRectangle[2]-14;

    var fld = this.addField("ComboDatePrint", "text", i, aRectangle );

    var fld = this.getField("ComboDatePrint." + i);

    fld.alignment = "center";

    fld.textSize = 11;

    fld.textColor = color.black;

    fld.textFont = font.Times;

    fld.fillColor = color.white;

    fld.rotation = 270;

    fld.readonly = true;

    fld.print = true;

    fld.display = display.noView;
    } end of true block
    else { // block of code for not >=

    var nRot = this.getPageRotation(i);

    var aRectangle = this.getPageBox( {nPage: i} );

    aRectangle[1] = aRectangle[3]+14;

    var fld = this.addField("ComboDatePrint", "text", i, aRectangle );

    var fld = this.getField("ComboDatePrint." + i);

    fld.alignment = "center";

    fld.textSize = 11;

    fld.textColor = color.black;

    fld.textFont = font.Times;

    fld.fillColor = color.white;

    fld.readonly = true;

    fld.print = true;

    fld.display = display.noView;
    } // end if else bocks

    } // end page loop


    var myWillPrintScript = 'var fld = this.getField("ComboDatePrint"); fld.value = "EXPIRATION. Vence: " + util.printd("dd/mm/yyyy h:MM:ss tt",new Date(new Date().getTime()+1000*60*60*24*5)) \r'

    this.setAction("WillPrint", myWillPrintScript);
    Thom Parker
    Community Expert
    Community Expert
    December 1, 2008
    You've got a few syntax problems. First, don't end the "if" statment with a semi-colon. This ends the if block. Next, the lines of code inside the "if" have to be blocked off with curly braces "{}". That's why the error is on the "else if", it's not connected to an "if" statment.

    Now, I think you'd be better off getting the page rotation first, and then using it purely for determining the field rotation. The field placement should be the same either way.

    Thom Parker
    WindJack Solutions
    The source for PDF Scripting Info
    pdfscripting.com

    The Acrobat JavaScript Reference, Use it Early and Often
    http://www.adobe.com/devnet/acrobat/javascript.html
    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
    Participating Frequently
    December 1, 2008
    I am trying to use >= and < in order to know when the page is horizontal and when is vertical