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

    Inspiring
    July 3, 2008
    Check the JavaScript API Reference, "TimesNewRoman" is not the name for use in JavaScript.

    The following script works without a problem:

    // Times New Roman Print Date //
    app.calculate = false; // turn off auto calculate

    // add field to each page
    for (var i = 0; i < this.numPages; i++) {

    var aRectangle = this.getPageBox( {nPage: i} ); // get media box
    aRectangle[1] = aRectangle[3] + 50; // set location
    var fld = this.addField( {cName: "ComboDatePrint", cFieldType: "text",
    nPageNum: i, ocoords: aRectangle} ); // add field
    fld.alignment = "center"; // center contents
    fld.textSize = 8; // text size
    fld.textColor = color.black; // font color
    fld.textFont = font.Times; // font name
    fld.fillColor = color.white; // fill color
    fld.readonly = true; // read only
    fld.print = true; // print field
    fld.display = display.visible; // display field

    } // end for each page

    app.calculate = true; // restore auto calculate

    // add WillPrint script to populate the form field
    this.setAction({cTrigger: "WillPrint",
    cScript: "var fld = this.getField(\"ComboDatePrint\"); fld.value = \"PRINT DATE: \" + util.printd(\"mmmm dd, yyyy\",new Date()); \r"});
    Bernd Alheit
    Community Expert
    Community Expert
    July 3, 2008
    > fld.textFont = font.TimesNewRoman;

    font.TimesNewRoman is undefined.
    Participant
    July 3, 2008
    Thom-
    Here is what was in the console window:

    Acrobat Database Connectivity Built-in Functions Version 8.0
    Acrobat EScript Built-in Functions Version 8.0
    Acrobat Annotations / Collaboration Built-in Functions Version 8.0
    Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
    Acrobat Multimedia Version 8.0
    Acrobat SOAP 8.0

    InvalidSetError: Set not possible, invalid or unknown.
    Field.textFont:9:Batch undefined:Exec

    InvalidSetError: Set not possible, invalid or unknown.
    Field.textFont:9:Batch undefined:Exec

    InvalidSetError: Set not possible, invalid or unknown.
    Field.textFont:9:Batch undefined:Exec

    InvalidSetError: Set not possible, invalid or unknown.
    Field.textFont:9:Batch undefined:Exec

    After the routine is run, we open the document and print to see if the routine worked. And nothing prints.

    I can send a sample document if you think it would help.
    Judy
    Thom Parker
    Community Expert
    Community Expert
    July 3, 2008
    Hello Judy,
    How is the script you posted above being executed? You are reporting an unusal problem so please be specific in how the process proceeds.

    Are there any errors reported in the Console Window?

    The only way for the font to be causing a problem is if it did not exist at the time the assignment was made. Acrobat instantly embeds a font as soon as it is assigned to a field.
    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
    Participant
    July 3, 2008
    Thom-
    Would you mind taking a look at the last few messages on this thread? I addressed them to Steve Foxall by mistake. Perhaps you would have some knowledge about my java script not working when changing the font. Thanks in advance for your insight.
    Judy McKinney
    steve_foxall
    Participating Frequently
    July 3, 2008
    Ah, confusion. Maybe there is another Steve in the thread? I don't use header/footer scripts: my short script is in a text field (where the font is simply selected rather than written as code), so can't offer any help with this.
    Participant
    July 3, 2008
    Hi Steve-
    I haven't gotten it to work off line. Attached are sample documents that we are using to test this. One already has the batch run w/the Helvetica font in the JavaScript which we can't get to change (date test.pdf). The other did not receive the JS routine at all even after we made TimesNewRoman and embedded font. Below is the script we are using:

    /* Times New Roman Print Date */

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

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

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

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

    fld.alignment = "center";

    fld.textSize = 8;

    fld.textColor = color.black;

    fld.textFont = font.TimesNewRoman;

    fld.fillColor = color.white;

    fld.readonly = true;

    fld.print = true;

    fld.display = display.visible; }

    var myWillPrintScript = 'var fld = this.getField("ComboDatePrint"); fld.value = "PRINT DATE: " + util.printd("mmmm dd, yyyy",new Date()); \r'

    this.setAction("WillPrint", myWillPrintScript);

    Thank you, Steve, for taking a look at this.

    Regards,

    Judy
    steve_foxall
    Participating Frequently
    July 2, 2008
    You mean doesn't work online, or at all?
    I tried 3 different font changes in a typical document, with no issues. Can you email me the document to test?
    Participant
    July 2, 2008
    Steve-
    We are using the java script mentioned in this thread. However, we have discovered that the font must be = to an embedded font in the pdf document for the routine to work via an online publisher. We have tried to change the font to Arial or TimesNewRoman which are both embedded fonts in the document. The JS routine will not work after we change the font. Can you help with this?
    Thank you,
    Judy
    Participating Frequently
    December 18, 2007
    Hi All:<br /><br />This Code works to add an expiration date at the bottom of each page of a PDF document.<br /><br /><< FOR USERS OF ACROBAT PROFESSIONAL == This has limited use, since most users will not have Acrobat Professional but everyone has Acrobat Reader>><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 /><< == FOR ACROABT READERS ===========================><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 /> <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' <br /><br />this.setAction("WillPrint", myWillPrintScript); <br /><br /><< == END CODE ========================================== >><br /><br />FYI: How to Write a Batch Process that will process all files in a selected folder and add custom code to each file.<br />==================================================================<br /><br />In Acrobat 8.0 Professional, I clicked on Menu:<br /><br />Advanced --> Document Processing --> Batch Processing<br />-- <Click on New Sequence Button> --> <Choose a name for this sequence: Test><br /><br />In the <Edit Batch Sequence - Test Dialog Box><br />Click on <1. Select Commands> button<br />In the <Edit Sequence Dialog Box><br /> Click on <JavaScript -- Execute JavaScript> from the List box on left side. Then click on the <Add> button. Next click on the <Edit> button. Paste the Code above into the <Create and Edit JavaScripts> text-area and then click on <OK><br />Then Click <OK> to close the <Edit Sequence> dialog box.<br /><br />Next In the <Edit Batch Sequence - Test Dialog Box> <br />Click on <2. Run commands on: Selected Folder - and specify the folder><br /><br />Click on <3. Select output location: In my case I selected Same Folder as Originals><br /><br />Finally click on <Output Options if necessary> then click on <OK><br /><br />Next in the <Batch Sequences Dialog Box> click on the Batch. In this case <test> and then click on <Run Sequence>.<br /><br />That will execute the sequnce.<br /><br /><<The Acrobat Reader code creates a field on each page of the PDF's>><br />To actually see where the Code is that Prints Today's date:<br /><br />1. Open one of the files which was processed using the Batch above.<br />2. Click on <Advanced -- Document Processing -- Set Document Actions> You should see a Green bubble next to the <Document Will Print> document action. Click on Edit to actually see the code when a user goes to print the PDF. In this case it will show:<br /><br />var fld = this.getField("ComboDatePrint"); fld.value = "This Document Expires at: " + util.printd("mmmm dd, yyyy",new Date()) + " 11:59 PM"; <br /><br />3. Click on <OK> to close the JavaScript Editor.<br /><br />Hope someone will benefit from these instructions.<br />Gyan