Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Add Curent Date & Time to PDF when Printed

Guest
Oct 06, 2010 Oct 06, 2010

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.

33.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
LEGEND ,
Oct 06, 2010 Oct 06, 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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2010 Oct 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 07, 2010 Oct 07, 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);

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 18, 2011 Jan 18, 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2011 Jan 18, 2011

The entire script will add a field, but you can add the field. Once the field has been added, you can move it wherever you want it and resize it as necessary.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 18, 2011 Jan 18, 2011

thanks for the quick response. i've been trying that.

and how about the current time?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 19, 2011 Jan 19, 2011

The code is a little cumbersome for displaying the date.

Once a field is established, I would use the following code for inserting the text the text field:

var sNoticeField = "PrintField"; // name of field for printed notice

var oNow = new Date(); // get the JS date time object

// build format string to display

var sText =  "Printed on "; // date lead in text

sText += util.printd("mmmm d, yyyy", oNow); // formatted date string

sText += ' at '; // time lead in

sText += util.printd("h:MM tt', oNow); // formatted time string

this.getField(sNoticeField).value = sText; // set the field value

More information about the 'util.printd' method is in the Acrobat JS API Reference.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 13, 2012 Aug 13, 2012

Realize this thread is old but is answering my problem EXCEPT I don't see how to add the time stamp.  I have the code listed by kmcavinue20rrf working but it doesn't show the tume.  If I try to change by adding the code by GKaiseril, I get an error syntaxerror unterminated string literal for the last line of the code.  (this.getField(sNoticeField).value = sText; // set the field value)

Below is how I have the code with the change,  did I insert the code incorrectly?  I have not worked with programming Acrobat previously so would appreciate any assistance getting the date into this stamp.  Otherwide the original code is perfect!

// 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;

    }

var sNoticeField = "PrintField"; // name of field for printed notice

var oNow = new Date(); // get the JS date time object

// build format string to display

var sText =  "Printed on "; // date lead in text

sText += util.printd("mmmm d, yyyy", oNow); // formatted date string

sText += ' at '; // time lead in

sText += util.printd("h:MM tt', oNow); // formatted time string

this.getField(sNoticeField).value = sText; // set the field value

              

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

this.setAction("WillPrint", myWillPrintScript);

this.setAction("DidPrint", myDidPrintScript);

Thanks

Sue

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 13, 2012 Aug 13, 2012
LATEST

Found the answer here:  http://forums.adobe.com/message/1097488

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines