Skip to main content
Participating Frequently
November 1, 2005
Question

Add current date to PDF documents

  • November 1, 2005
  • 127 replies
  • 43043 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

    Inspiring
    December 1, 2008
    The equality operator is "==" not "=", which is the set operator.
    Participating Frequently
    December 1, 2008
    Hi Thom,

    I am trying with this script in order to diferetiate the horizontal and Vertical pagel, but I get a problem in syntax with the condition if/else

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

    {

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

    if (rCrop[1] >= rCrop[2]);

    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;

    else if (rCrop[1] < rCrop[2]);

    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;

    }



    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
    Getting the page rotation will tell you how the field needs to be rotated for correctly displaying the text. Give it a try.

    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
    Hi Thom,

    I try a document with just horizontal oriented pages and I filled the box in black color and the letters in white, and I noticed that box its correctly placed according coordinates, but the text inside the box is rotated. In veritcal pages the text and box are aligned. The getPageRotation method could fix this issue?
    Thom Parker
    Community Expert
    Community Expert
    December 1, 2008
    You can get the page rotation before adding the annotation and put some intelligence into setting the field rotation.

    use:
    var nRot = this.getPageRotation(i);

    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
    Hi Thom....Terrific Support!!!!

    Great! I have followed your advise and now the document is printed just like I wanted, but I have another issue (I hope the last one).....I have a document with multiple alternates letter/legal pages. The legal pages are in horizontal orientation and the problem is the same like above but only in legal pages, the vertical oriented pages are OK.

    Thank you very much for your help!!!
    Thom Parker
    Community Expert
    Community Expert
    December 1, 2008
    You've done execellent so far!!

    The problem is that all of the fields have the same name. They are in essence the same field. The appearance of the field on the page is called a Widget. Anything having to do with the field appearance is a Widget property and only affects the field on a specific page.

    The addField function always returns the object for the first widget, even though it creates a new widget. You have to explicitly acquire the widget to set it's properties. And this is done with the widget dot notation.

    this.getField("ComboDatePrint.1")

    this code acquires the 2nd widget for the "ComboDatePrint" field.

    Add this line of code into your script right after the addField()

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

    I think that should do the trick.

    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
    Hi Thom,

    Thank you very much for your support and your quick response. I dont have much experience programming in javascript under Acrobat. After take a look to the links that you have attached, I could rotate and relocate the text in the page, but after run the secuence I realized that in a document with several pages, just the first page shows the text correctly, the other ones are horizontal and out of location. I have pasted below the code with the revisions that I have done according to the articles that you sent me.

    Kind Regards.

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

    {

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

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

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

    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;

    }



    var myWillPrintScript = 'var fld = this.getField("ComboDatePrint"); fld.value = "PRINT EXPIRATION: " + 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
    November 30, 2008
    If you want the text rotated then set the field's "rotation" property.

    fld.rotation = 270:

    If you want the letters arranged vertically then you can make the fld tall and thin, and set the fild's multiline option.

    Either way you'll need to set the field'd position and size for it to display correctly. Look at these articles.

    http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/page_bounds/

    http://www.acrobatusers.com/tutorials/2007/js_add_buttons_to_pdf/

    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
    November 30, 2008
    Hi,

    How can i do in order to place this text in vertical aligment in the right side of the page?