Skip to main content
Participating Frequently
November 1, 2005
Question

Add current date to PDF documents

  • November 1, 2005
  • 127 replies
  • 43045 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 18, 2007
    Hi Geo:<br /><br />Thanks so much for the code revision. However when I executed your code aftering revising my batch script, I get an error in the Javascript debugger: <br /><br />syntax error<br />2:Doc:Will Print<br /><br /><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<br />for (var i = 0; i < this.numPages; i++) <br /><br />{ <br /><br />var aRectangle = this.getPageBox( {nPage: i} ); <br /><br />aRectangle[1] = aRectangle[3] +14; <br /><br />var fld = this.addField("ComboDatePrint", "text", i, aRectangle ); <br /><br />fld.alignment = "center"; <br /><br />fld.textSize = 7; <br /><br />fld.textColor = color.blue; <br /><br />fld.textFont = font.HelvB; <br /><br />fld.fillColor = color.white; <br /><br />fld.readonly = true; <br /><br />fld.print = true; <br /><br />fld.display = display.noView; <br />} <br /><br /> <br />var myWillPrintScript = 'var fld = this.getField("ComboDatePrint"); fld.value = "This Document Expires at: " + util.printd("mmmm dd, yyyy",new Date()) + " 11:59 PM"; \r' + '} \r' <br /><br />this.setAction("WillPrint", myWillPrintScript); <br /><br />>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><br /><br />I ran the batch using: Advanced --> Document Processing --> Batch Processing --> Run Sequence (selected custom batch file named <ReaderAddExpirationDatesToDocs> with your code). <br /><br />The batch ran without any errors.<br /><br />But when I open one of the target PDF's which the batch modified, I get the message<br /><br />Syntax error<br />2:Doc:Will Print<br /><br />Thanks so much for your help. I am not at all good at Scripting in acrobat and your help is very much appreicated.<br /><br />GC
    Inspiring
    December 18, 2007
    When using Reader, one can not create a form field with JavaScript, so one has to use Acrobat Professional to crate the the field, and then modify the will print script to just change the field's value.

    A possible batch processing script to add the field to each page of a PDF and the "Will Print" action to the PDF.

    // for each page of open PDF add the following field:
    for (var i = 0; i < this.numPages; i++) {
    var aRectangle = this.getPageBox( {nPage: i} ); // get page size
    aRectangle[1] = aRectangle[3] +14; // set location
    var fld = this.addField("ComboDatePrint", "text", i, aRectangle ); // define field to add
    'fld.alignment = "center"; // alignment of field
    fld.textSize = 7; // text size for field
    fld.textColor = color.blue; // text color for field
    fld.textFont = font.HelvB; // font for field
    fld.fillColor = color.white; // fill color
    fld.readonly = true; // write protect the field
    fld.print = true; // print field
    fld.display = display.noView; // do not display field
    } // end for loop

    // add will print script to populate field - all fields with same name will have the same value
    var myWillPrintScript = 'var fld = this.getField("ComboDatePrint"); fld.value = "This Document Expires at: " + util.printd("mmmm dd, yyyy",new Date()) + " 11:59 PM"; \r' + '} \r' this.setAction("WillPrint", myWillPrintScript);
    Participating Frequently
    December 18, 2007
    << CODE works in Acrobat Professional but NOT in Reader - Please help>><br /><br />Hello Everyone:<br /><br />I am using Acrobat 8.0 Professional.<br /><br />I created a Batch File that Prints at the bottom of each page <This document expires at: Todays date>. Using Acrobat Professional, I am able to apply this code to all PDF's in a selected folder using the Batch Processing menu.<br /><br /><< == CODE BEGIN ====================================== >> <br /><br />var myWillPrintScript = 'for (var i = 0; i < this.numPages; i++){\r'<br />+ 'var aRectangle = this.getPageBox( {nPage: i} ); \r'<br />+ 'aRectangle[1] = aRectangle[3] +14; \r \r'<br />+ 'var fld = this.addField("ComboDatePrint", "text", i, aRectangle ); \r \r'<br />+ 'fld.alignment = "center"; \r'<br />+ 'fld.textSize = 7; \r'<br />+ 'fld.textColor = color.blue; \r'<br />+ 'fld.textFont = font.HelvB; \r'<br />+ 'fld.fillColor = color.white; \r'<br />+ 'fld.readonly = true; \r'<br />+ 'fld.print = true; \r'<br />+ 'fld.display = display.noView; \r \r'<br />+ 'fld.value = "This Document Expires at: " + util.printd("mmmm dd, yyyy",new Date()) + " 11:59 PM"; \r'<br />+ '} \r'<br />this.setAction("WillPrint", myWillPrintScript);<br /><br /><< == CODE END ======================================== >> <br /><br />This code works perfectly for users who have Acrobat Professional Installed. When they print the PDF, the selected message prints on the bottom of each page.<br /><br />However NOTHING prints for users using Acrobat Reader 8.0.<br /><br />They get an error message if the Error Console is turned on that reads:<br /><<<br />NotAllowedError: Security settings prevent access to this property or method <br />Doc.addField:5:Doc undefine:Will Print<br />>><br /><br />I only have 12 users in our company, and only 3 have Acrobat Professional because of cost reasons. Is there a way to bypass the security message, and permit the date to print for users using only Acrobat Reader.<br /><br />Thanks so much for your help.<br />GC
    Inspiring
    December 13, 2007
    Acrobat Standard only allows editing the JavaScript in bookmarks, page actions, print actions, and save actions these options do not provide direct edit of the document level or form scripts. You would need a user that knows how to create a bookmark that can open the JavaScript Console and then know enough Acrobat JavaScript to modify the field level and add document level scripts. The modification of JavaScripts by the JavaScript statements is tricky for most programers and if they are good enough to do that they should know better than changing them.

    Using Acrobat's password security can lock the PDF to limit entering form data and printing the form, then the user would need to crack the password to modify the scripts. And if they did that your employer could have grounds for damages and termination.
    Participant
    December 13, 2007
    Hi Guys,
    I am having one more questions.
    In our company 90% of them use Acrobat Standard 7 and i believe they will have option to edit the Javascript which i have written. if that is possible then, how can i make that not happen.
    because, i will creating the PDF and publishing to our internal website and the user community will download it and print it and use it. If i cannot avoid changing this javascript, any techie user can modify and change and this may create problems.

    Any ideas?

    thanks,
    Mahesh
    Participant
    December 12, 2007
    thanks alot guys. it worked like charm...
    i love this forum...
    gr8!!!

    Mahesh
    steve_foxall
    Participating Frequently
    December 11, 2007
    mah*****
    If your users are only using Reader they won't get the prompt.

    Geo
    Nevertheless, it drives me mad too (using Acrobat Pro) so that bit of code is a little gold nugget...Thank-you!
    Inspiring
    December 11, 2007
    In the script that sets the current date add:

    this.dirty = false; // prevent save prompt

    to the end of the script to clear the docuemnt variable that tracks if any changes have been made.
    Participant
    December 11, 2007
    Hi,
    Even i am having a similar requirment. I have a document where i have added a form field (name: Today) and a Javascript just to assign the value of current system date to this value and show this date when i print the document. everything is fine but when i close the documnet, adobe is prompting to save the document. how can i avoid this? because, printing the system is done background and the user doesn't know it. but the user will be surprised when he see that adobe asking to save the PDF document which he is not aware of changed anything.

    any ideas?

    thanks,
    Mahesh
    Inspiring
    September 17, 2007
    // 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); // get page size quads<br />/* elements of quad array<br />[0] - lower left x; [1] - lower left y <br />[2] - upper right x; [3] - upper right y<br />*/<br />rectField[2] = rectField[2] - 14; // Place field 14 points from upper right height<br />ofield = this.addField({cName: strModName,cFieldType: "text", nPageNum:i ,oCoords: rectField});<br />ofield.alignment = "center"; //This is the text alignment of the field <br />ofield.multiline = true; 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 ofield.readonly = true; <br />} // end for numPages loop <br /><br />} // end create field<br /><br />// Add update upon open to Document Script <br /> var strJS = 'var ofield = this.getField("DocMessage");'; <br /> strJS += 'ofield.value = "Intellectual Property of My Company - CONFIDENTIAL. ";';<br /> strJS += 'var oToday = new Date();';<br /> strJS += 'ofield.value += " Document printed " + util.printd("dd mmm yyyy", new Date(oToday,getFullYear(), oToday.getMonth(), (oToday.getDate() + 14) ) ) + ".";'; <br /> this.addScript("AddMessage",strJS);