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
    December 23, 2005
    Hi Everyone -<br /><br />Thanks to Dimitri, I was able to do exactly what I wanted to do by using the following code:<br /><br /> // Check for existing field and make sure it's on the first page<br /> var strModName = "DocMessage";<br /> var ofield = this.getField("DocMessage");<br /><br /> // Create Field if it doesn't exist<br /><br /> if(ofield == null)<br /> {<br /> // Field is the width of the page, on the bottom of the page<br /> // and 40 points high (72pts/inch)<br /><br /> for(var i=0;i<this.numPages;i++)<br /> {<br /> var rectField = this.getPageBox("Crop",i);<br /> rectField[1] = rectField[3] + 14; // Set Top<br /> ofield = this.addField({cName: strModName,cFieldType: "text",<br /> nPageNum:i ,oCoords: rectField});<br /> ofield.alignment = "center"; //This is the text alignment of the field<br /> ofield.multiline = true;<br /> ofield.textSize = 8; <br /> ofield.textFont = "Arial";<br /> ofield.display = display.noView; //This is hidden on the page but printable to make viewable change to display.visible or noView<br /> ofield.readonly = true;<br /> }<br /> }<br /><br /> // Add Field to Document Script<br /> var strJS = 'var ofield = this.getField("DocMessage");';<br /> strJS += 'ofield.value = "Intellectual Property of My Company - CONFIDENTIAL. ";';<br /> strJS += 'ofield.value += " Document printed " + util.printd("ddmmmyyyy",new Date()) + ".";';<br /> this.addScript("AddMessage",strJS);<br /><br />However - Now I would like to change the message to say that the document expires on a future date. For example, 14 days from today. I found an example of how to do this on page 266 of the Adobe JS Scripting Guide and have followed it to the letter, but it is not working. Here is the modified code:<br /><br /> // Check for existing field and make sure it's on the first page<br /> var strModName = "DocMessage";<br /> var ofield = this.getField("DocMessage");<br /><br /> // Create Field if it doesn't exist<br /><br /> if(ofield == null)<br /> {<br /> // Field is the width of the page, on the bottom of the page<br /> // and 40 points high (72pts/inch)<br /><br /> for(var i=0;i<this.numPages;i++)<br /> {<br /> var rectField = this.getPageBox("Crop",i);<br /> rectField[1] = rectField[3] + 14; // Set Top<br /> ofield = this.addField({cName: strModName,cFieldType: "text",<br /> nPageNum:i ,oCoords: rectField});<br /> ofield.alignment = "center"; //This is the text alignment of the field<br /> ofield.multiline = true;<br /> ofield.textSize = 8; <br /> ofield.textFont = "Arial";<br /> ofield.display = display.noView; //This is hidden on the page but printable to make viewable change to display.visible or noView<br /> ofield.readonly = true;<br /> }<br /> }<br /><br /> /* Create a date object containing the current date. */<br /> var d1 = new Date();<br /> /* num contains the numeric representation of the current date. */<br /> var num = d1.valueOf();<br /> /* Add fourteen days to todays date, in milliseconds. */<br /> /* 1000 ms/sec, 60 sec/min, 60 min/hour, 24 hours/day, 14 days */<br /> num += 1000 * 60 * 60 * 24 * 14;<br /> /* Create our new date, 14 days ahead of the current date. */<br /> var d2 = new Date(num);<br /> // Add Field to Document Script<br /> var strJS = 'var ofield = this.getField("DocMessage");';<br /> strJS += 'ofield.value = "Intellectual Property of My Company - CONFIDENTIAL. ";';<br /> strJS += 'ofield.value += " Document expires on " + util.printd("ddmmmyyyy", d2) + ".";';<br /> this.addScript("AddMessage",strJS);<br /><br />The resulting output is simply: "Intellectual Property of My Company - CONFIDENTIAL." The part of the message regarding the expiration date doesn't even show up.<br /><br />Anyone have any suggestions?
    steve_foxall
    Participating Frequently
    November 14, 2005
    You're welcome Sven.
    I currently only create one or two documents each month that need this text, so no, I just copy & paste (and reposition). I guess the batch process that takes up most of this thread could handle it, but not automatically, and I've not used it yet. We're thinking of putting this warning on all our pdf's of drawings sometime soon (7000+) so I'll be looking to batch it if possible. One problem seems to be that pasting buttons and text fields always places the field in the middle of the document, so some javascript similar to that described in earlier messages will be needed to get things in the right place.

    Steve.
    Participant
    November 14, 2005
    Hi Steve,

    thanks you for your help! It works great!
    Do you know a way to insert those two textfields to every new created PDF-File?

    Greetings

    Sven
    steve_foxall
    Participating Frequently
    November 12, 2005
    fascinating stuff...!
    Unless its a US thing, the centration problem may be due to too many L's in 'alignment'.

    Steve (GB)
    Bernd Alheit
    Community Expert
    Community Expert
    November 11, 2005
    Use:

    util.printd("dd/mmm/yyyy", new Date())

    not:

    util.printd("dd/mmm/yyyy", Date())

    in your script. The word 'new' is important.
    Participating Frequently
    November 11, 2005
    I did not print the document to paper if that is what you are asking. Was is supposed to show up correct when printed?

    If so...is there some way to not show "Document printed on: 18524/EDU/17207" when the document is displayed on screen?
    Bernd Alheit
    Community Expert
    Community Expert
    November 11, 2005
    Did you see also "Document printed on: 18524/EDU/17207" on your printout?
    Participating Frequently
    November 11, 2005
    Bernd -

    I added the code you provided to the existing code, but the message that displays in the PDF file is:

    "Document printed on: 18524/EDU/17207"

    Here is the script I am using, with your last code snipped added per your instructions:

    for (var p = 0; p < this.numPages; p++)
    {
    var fd = this.addField("Date", "text", p, [72,0, 540,16]);
    fd.textSize=8;
    fd.value = "Document printed on: " + util.printd("dd/mmm/yyyy", Date());
    fd.allignment = "right";
    fd.fillColor = color.transparent;
    fd.textColor = color.gray;
    fd.borderColor = color.gray;
    fd.readonly = true;

    var txtWillPrint = 'var d = this.dirty;\r'
    + 'var fd = this.getField("Date");\r'
    + 'fd.value = "Document printed on: " + '
    + 'util.printd("dd/mmm/yyyy", new Date());\r'
    + 'this.dirty = d;';

    this.setAction("WillPrint", txtWillPrint);

    }
    Bernd Alheit
    Community Expert
    Community Expert
    November 11, 2005
    Add the following lines to the end of your script:

    var txtWillPrint = 'var d = this.dirty;\r'
    + 'var fd = this.getField("Date");\r'
    + 'fd.value = "Document printed on: " + '
    + 'util.printd("dd/mmm/yyyy", new Date());\r'
    + 'this.dirty = d;';

    this.setAction("WillPrint", txtWillPrint);
    Participating Frequently
    November 11, 2005
    Hi Dimitri -

    Please try replying to davewest01 at yahoo dot com.

    Thanks,
    Dave