Skip to main content
Participating Frequently
November 1, 2005
Question

Add current date to PDF documents

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

    Participating Frequently
    January 10, 2009
    Hi Thom,
    What you mean is that I can create a batch script that adds the field and the script from Msg#29 to a folder full of PDF files. This gets around the problem that the .addField command doesn't work when the PDF is printed by a Reader user, since the field already exits.
    Am I stating this correctly?

    Thanks,
    -Tom
    Thom Parker
    Community Expert
    Community Expert
    January 10, 2009
    You can create an automation script for adding both the field and the script to any PDF that's open in Acrobat Pro.

    Here's an article on an automation script for adding a button to the PDF. You'd use a very similar technique.

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

    Search for Acrobat Folder Level Scripts and toolbar buttons. There's plenty on this exact issue already out there.

    In fact, this is already a script that comes with AcroButtons, which is a tool for creating toolbar buttons in Acrobat.

    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
    January 10, 2009
    You mean manually add the field and code from Msg#29 to each PDF?
    -Tom
    Bernd Alheit
    Community Expert
    Community Expert
    January 10, 2009
    Add the field and the script in Adobe Acrobat. See message #29.
    Participating Frequently
    January 10, 2009
    Bernd,
    All my users have Reader. Is there no work-around to have this script run when a user prints from Reader?
    Thanks,
    -Tom
    Bernd Alheit
    Community Expert
    Community Expert
    January 6, 2009
    Add character ';' before this.setAction.

    The script will not run in Adobe Reader. Adobe Reader can't use the method this.addField.
    Participant
    January 5, 2009
    I am using Acrobat Professional 8.1 however 99% of the users of the files I am creating are using Reader.

    I have used the two sets of code from msg 78. I have tried to create two scripts; the first using the 'Professional' code, and the second using the 'Reader' code.

    I have two questions.

    Question 1
    Using the code labelled 'Professional', I get the following error when trying to close the JavaScript Editor.

    missing ; before statement 1: at line 2

    It seems that the entire code when copied & pasted is on Line 1? Is this correct or should there be some line breaks inserted?

    Question 2
    I successfully created a script using the code labelled 'Reader'. Then I ran the script using the Batch Processing also described in Msg78. (This was all accomplished using Pro.)

    So far, all this works great however, when I open and print the PDF file from Reader there is no text. However opening and printing the same file in Professional, it has worked beautifully.

    Is the code in Msg 78 mislabelled? Is the code labelled Reader really for Professional and vice versa?

    If this is the case, then this makes sense. However I do need the answer to Question 1 as well in order to make this work for my Readr users.

    Thanks!
    Phil
    Participating Frequently
    January 1, 2009
    Hi Bernd,

    Happy New Year! I tried your script and it works great!! I made my little wording changes without breaking the script. I still haven't found the difference between your script and the Msg#53 script.

    Thanks very much!

    Tom
    Bernd Alheit
    Community Expert
    Community Expert
    January 1, 2009
    var strModName = "DocMessage";<br /><br />var ofield = this.getField("DocMessage");<br /><br />if(ofield == null) {<br /><br /> for(var i=0;i<this.numPages;i++) {<br /><br /> var rectField = this.getPageBox("Crop",i);<br /><br /> rectField[1] = rectField[3] + 14;<br /><br /> ofield = this.addField({cName: strModName,cFieldType: "text", nPageNum:i ,oCoords: rectField});<br /><br /> ofield.alignment = "center"; <br /><br /> ofield.multiline = true;<br /><br /> ofield.textSize = 8;<br /><br /> ofield.textFont = "Arial";<br /><br /> ofield.display = display.noView;<br /><br /> ofield.readonly = true;<br /> } <br />}<br /><br />var strJS = 'var ofield = this.getField("DocMessage");';<br /><br />strJS += 'var theDate = (new Date((new Date()).valueOf() + 1000 * 60 * 60 * 24 * 14));';<br /><br />strJS += 'ofield.value = "PRINTED COPIES OF THIS DOCUMENT WILL EXPIRE AT MIDNIGHT ON";';<br /><br />strJS += 'ofield.value += " " + util.printd("ddmmmyyyy",theDate) + ". Do not use after this date.";';<br /><br />this.addScript("AddMessage",strJS);
    Participating Frequently
    January 1, 2009
    Bernd,

    Can you make this code work? I need to add the print date and "Uncontrolled Copy" to dozens of PDF so that the message isn't visible to users viewing the document on screen, but will be there whenever anyone prints the PDF. That is pretty close to the way the script in message #53 works.

    Thanks,

    Tom