Skip to main content
October 6, 2010
Answered

Add Curent Date & Time to PDF when Printed

  • October 6, 2010
  • 1 reply
  • 42240 views

This is my first post so please excuse any ignorance.

Basically we are in the process of creating electronic copies of SOP’s and putting them on our file server for all staff to access. Due to regulations, when these SOP’s are printed they would need to have the current date and time in which the SOP was printed, ideally like a watermark faded diagonally across the page but even if it was something on the bottom or top this would also do the trick.

It should read "Only Valid on Date of Printing - <Current Date><Current Time>

Could somebody please tell me if something like this is possible by incorporating JavaScript into the PDF.

Any assistance I would be grateful.

Thanks.

Keith.

    This topic has been closed for replies.
    Correct answer gkaiseril

    You need to add a form field to PDF and then you will need to add a document action script for the "Will Print" action that adds any text and date and time data as needed. There are a number of post about how to do this, you can use the search box to find them.

    1 reply

    gkaiserilCorrect answer
    Inspiring
    October 6, 2010

    You need to add a form field to PDF and then you will need to add a document action script for the "Will Print" action that adds any text and date and time data as needed. There are a number of post about how to do this, you can use the search box to find them.

    October 7, 2010

    GKaiseril

    Thank you so much, I got it and it worked perfect courtesy of "hardDriver2". For anybody else who is looking to do this see below.

    ---------------------------------------------

    // Description: This script adds a text field to the left side of all

    // pages. It also sets a doc level JavaScript that executes when the

    // document is printed and fills the field with date.

    // Add field to each page of form

    var inch = 72;

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

        // create rectangle quads for field

        var aRect = this.getPageBox( {nPage: p} );

        aRect[0] = 0.0;

        aRect[1] = 0.0;

        aRect[2] = 26.0;

        aRect[3] = 792;

        // now construct text field to fill with date information

        var f = this.addField("PrintField", "text", p, aRect )

        f.delay = true;

        f.textSize = 16;

        f.textFont = font.HelvB;

        f.textColor = color.black;

        f.alignment = "center";

        f.readonly = true;

        f.print = true;

        f.hidden = true;

        f.delay = false;

    }

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

        // rotate the text 

        var f = this.getField("PrintField." + p)

        f.rotation = 90;

        }

    // Adds a doc level script to populate text field when doc prints from

    // Acrobat or the free Adobe Reader. Note: the '\r' character represents a

    // carriage return.

    var myWillPrintScript = 'var f = this.getField("PrintField"); \r' + 'f.hidden = false; \r' + 'var d = new Date(); \r' + 'var year = d.getYear()+1900; \r' + 'f.value = "THIS DOCUMENT ONLY EFFECTIVE ON " + (d.getMonth()+1) + "/" + d.getDate() + "/" + year; \r'

    var myDidPrintScript = 'var f = this.getField("PrintField"); \r'

                               + 'f.value = ""; \r'

                               + 'f.hidden = true; \r'

                   

    // Now set the scripts to execute on the Will/Did Print events.

    this.setAction("WillPrint", myWillPrintScript);

    this.setAction("DidPrint", myDidPrintScript);

    ---------------------------------------------------------

    New Participant
    January 19, 2011

    hi kmcavinue20rrf ,

    i'm trying to do the same thing. Thank you for sharing the javascript. But i was wondering, how do i include the current time?

    also, when this script is added on my pdf file, when my doc is printed out, the script is printed on the right side of the paper. I want it to print it on the bottom of the paper, how do i modify that? please assist. Thank you!