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

Add current date to PDF documents

New Here ,
Nov 01, 2005 Nov 01, 2005

Copy link to clipboard

Copied

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?

Views

41.2K
Translate

Report

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
replies 128 Replies 128
Community Expert ,
Dec 01, 2008 Dec 01, 2008

Copy link to clipboard

Copied

You've got a few syntax problems. First, don't end the "if" statment with a semi-colon. This ends the if block. Next, the lines of code inside the "if" have to be blocked off with curly braces "{}". That's why the error is on the "else if", it's not connected to an "if" statment.

Now, I think you'd be better off getting the page rotation first, and then using it purely for determining the field rotation. The field placement should be the same either way.

Thom Parker
WindJack Solutions
The source for PDF Scripting Info
pdfscripting.com

The Acrobat JavaScript Reference, Use it Early and Often
http://www.adobe.com/devnet/acrobat/javascript.html
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Report

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 ,
Dec 01, 2008 Dec 01, 2008

Copy link to clipboard

Copied

JavaScript requires you block out the block of code to execute when there a multiple lines of code to be excuted and an 'if' statement does not end with a ';' if you want a line of code or block of code to be executed. You use the "{" and "}" brackets to mark the start and end of the code block.

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

{

var rCrop = this.getPageBox("Crop",this.pageNum);

if (rCrop[1] >= rCrop[2]) { // start of block of code for true

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

aRectangle[0] = aRectangle[2]-14;

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

var fld = this.getField("ComboDatePrint." + i);

fld.alignment = "center";

fld.textSize = 11;

fld.textColor = color.black;

fld.textFont = font.Times;

fld.fillColor = color.white;

fld.rotation = 270;

fld.readonly = true;

fld.print = true;

fld.display = display.noView;
} end of true block
else { // block of code for not >=

var nRot = this.getPageRotation(i);

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

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

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

var fld = this.getField("ComboDatePrint." + i);

fld.alignment = "center";

fld.textSize = 11;

fld.textColor = color.black;

fld.textFont = font.Times;

fld.fillColor = color.white;

fld.readonly = true;

fld.print = true;

fld.display = display.noView;
} // end if else bocks

} // end page loop


var myWillPrintScript = 'var fld = this.getField("ComboDatePrint"); fld.value = "EXPIRATION. Vence: " + util.printd("dd/mm/yyyy h:MM:ss tt",new Date(new Date().getTime()+1000*60*60*24*5)) \r'

this.setAction("WillPrint", myWillPrintScript);

Votes

Translate

Report

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 ,
Dec 01, 2008 Dec 01, 2008

Copy link to clipboard

Copied

Hi dudes,

I have tried several ways, with var nRot = this.getPageRotation(i); but I cant locate the text inside Box in vertical position on landscape pages, even though the box itself is in Vertical Position

Any suggestions?

Thank you very much

Votes

Translate

Report

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 ,
Dec 01, 2008 Dec 01, 2008

Copy link to clipboard

Copied

It appears you are trying something far beyond your programinging level.

First I would change code so the fields are visible and fill in a value so I could see the results of my code:

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

{

var rCrop = this.getPageBox("Crop",i);

if (rCrop[1] >= rCrop[2]) { // start of block of code for true

var aRectangle = this.getPageBox( {nPage: i} );
aRectangle[0] = aRectangle[2]-14;
var fld = this.addField("ComboDatePrint", "text", i, aRectangle );
var fld = this.getField("ComboDatePrint." + i);
fld.alignment = "center";
fld.textSize = 11;
fld.textColor = color.black;
fld.textFont = font.Times;
fld.fillColor = color.white;
fld.rotation = 270;
fld.readonly = true;
fld.print = true;
fld.display = display.visible;

console.println("Page: " + i + " Page Rotation: " + this.getPageRotation(i));

} // end of true block
else { // block of code for not >=

var nRot = this.getPageRotation(i);
var aRectangle = this.getPageBox( {nPage: i} );
aRectangle[1] = aRectangle[3]+14;
var fld = this.addField("ComboDatePrint", "text", i, aRectangle );
var fld = this.getField("ComboDatePrint." + i);
fld.alignment = "center";
fld.textSize = 11;
fld.textColor = color.black;
fld.textFont = font.Times;
fld.fillColor = color.white;
fld.readonly = true;
fld.print = true;

fld.display = display.visible;

console.println("Page: " + i + " Page Rotation: " + this.getPageRotation(i));
} // end if else bocks

} // end page loop

this.getField("ComboDatePrint").value = "EXPIRATION. Vence: " + util.printd("dd/mm/yyyy h:MM:ss tt",new Date() )

And then run the code from the JavaScript Debugging Console and observe the results.

Votes

Translate

Report

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 ,
Dec 01, 2008 Dec 01, 2008

Copy link to clipboard

Copied

Thanks Geo. With this revision the pdf its just like I was looking for.

Very best Regards

Votes

Translate

Report

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
Community Beginner ,
Dec 29, 2008 Dec 29, 2008

Copy link to clipboard

Copied

I followed the instructions in Message #53 and pasted the code. I can't close the editor by selecting OK because it has an error: "missing } in compound statement 20: at line 21".
Can someone tell me how to fix it?
Thanks.

Votes

Translate

Report

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
Community Expert ,
Dec 30, 2008 Dec 30, 2008

Copy link to clipboard

Copied

Add the missing }

Votes

Translate

Report

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
Community Beginner ,
Dec 30, 2008 Dec 30, 2008

Copy link to clipboard

Copied

I simply don't know where to add the missing "}" Line 21 is the last line of code, but I don't know what "compound statement 20" means. I randomly added two "}}" at the end of line 21, creating: ...this.addScript("AddMessage",strJS);}}
and the error message disappeared. I could run the script, but no field with date was created in my test file. Can you help?
Thank you.

Votes

Translate

Report

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
Community Expert ,
Dec 31, 2008 Dec 31, 2008

Copy link to clipboard

Copied

For the correct use of the script you must add missing line breaks, e.g. for // and other code.

Votes

Translate

Report

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
Community Beginner ,
Dec 31, 2008 Dec 31, 2008

Copy link to clipboard

Copied

Bernd,

Can you make this code work? I need to add the print date and "Uncontrolled Copy" to dozens of PDF so that the message isn't visible to users viewing the document on screen, but will be there whenever anyone prints the PDF. That is pretty close to the way the script in message #53 works.

Thanks,

Tom

Votes

Translate

Report

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
Community Expert ,
Jan 01, 2009 Jan 01, 2009

Copy link to clipboard

Copied

var strModName = "DocMessage";<br /><br />var ofield = this.getField("DocMessage");<br /><br />if(ofield == null) {<br /><br /> for(var i=0;i<this.numPages;i++) {<br /><br /> var rectField = this.getPageBox("Crop",i);<br /><br /> rectField[1] = rectField[3] + 14;<br /><br /> ofield = this.addField({cName: strModName,cFieldType: "text", nPageNum:i ,oCoords: rectField});<br /><br /> ofield.alignment = "center"; <br /><br /> ofield.multiline = true;<br /><br /> ofield.textSize = 8;<br /><br /> ofield.textFont = "Arial";<br /><br /> ofield.display = display.noView;<br /><br /> ofield.readonly = true;<br /> } <br />}<br /><br />var strJS = 'var ofield = this.getField("DocMessage");';<br /><br />strJS += 'var theDate = (new Date((new Date()).valueOf() + 1000 * 60 * 60 * 24 * 14));';<br /><br />strJS += 'ofield.value = "PRINTED COPIES OF THIS DOCUMENT WILL EXPIRE AT MIDNIGHT ON";';<br /><br />strJS += 'ofield.value += " " + util.printd("ddmmmyyyy",theDate) + ". Do not use after this date.";';<br /><br />this.addScript("AddMessage",strJS);

Votes

Translate

Report

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
Community Beginner ,
Jan 01, 2009 Jan 01, 2009

Copy link to clipboard

Copied

Hi Bernd,

Happy New Year! I tried your script and it works great!! I made my little wording changes without breaking the script. I still haven't found the difference between your script and the Msg#53 script.

Thanks very much!

Tom

Votes

Translate

Report

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 05, 2009 Jan 05, 2009

Copy link to clipboard

Copied

I am using Acrobat Professional 8.1 however 99% of the users of the files I am creating are using Reader.

I have used the two sets of code from msg 78. I have tried to create two scripts; the first using the 'Professional' code, and the second using the 'Reader' code.

I have two questions.

Question 1
Using the code labelled 'Professional', I get the following error when trying to close the JavaScript Editor.

missing ; before statement 1: at line 2

It seems that the entire code when copied & pasted is on Line 1? Is this correct or should there be some line breaks inserted?

Question 2
I successfully created a script using the code labelled 'Reader'. Then I ran the script using the Batch Processing also described in Msg78. (This was all accomplished using Pro.)

So far, all this works great however, when I open and print the PDF file from Reader there is no text. However opening and printing the same file in Professional, it has worked beautifully.

Is the code in Msg 78 mislabelled? Is the code labelled Reader really for Professional and vice versa?

If this is the case, then this makes sense. However I do need the answer to Question 1 as well in order to make this work for my Readr users.

Thanks!
Phil

Votes

Translate

Report

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
Community Expert ,
Jan 06, 2009 Jan 06, 2009

Copy link to clipboard

Copied

Add character ';' before this.setAction.

The script will not run in Adobe Reader. Adobe Reader can't use the method this.addField.

Votes

Translate

Report

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
Community Beginner ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Bernd,
All my users have Reader. Is there no work-around to have this script run when a user prints from Reader?
Thanks,
-Tom

Votes

Translate

Report

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
Community Expert ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Add the field and the script in Adobe Acrobat. See message #29.

Votes

Translate

Report

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
Community Beginner ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

You mean manually add the field and code from Msg#29 to each PDF?
-Tom

Votes

Translate

Report

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
Community Expert ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

You can create an automation script for adding both the field and the script to any PDF that's open in Acrobat Pro.

Here's an article on an automation script for adding a button to the PDF. You'd use a very similar technique.

http://www.acrobatusers.com/tutorials/2007/06/js_add_buttons_to_pdf

Search for Acrobat Folder Level Scripts and toolbar buttons. There's plenty on this exact issue already out there.

In fact, this is already a script that comes with AcroButtons, which is a tool for creating toolbar buttons in Acrobat.

Thom Parker
WindJack Solutions
The source for PDF Scripting Info
pdfscripting.com

The Acrobat JavaScript Reference, Use it Early and Often
http://www.adobe.com/devnet/acrobat/javascript.html
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Report

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
Community Beginner ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Hi Thom,
What you mean is that I can create a batch script that adds the field and the script from Msg#29 to a folder full of PDF files. This gets around the problem that the .addField command doesn't work when the PDF is printed by a Reader user, since the field already exits.
Am I stating this correctly?

Thanks,
-Tom

Votes

Translate

Report

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
Community Expert ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Well, I didn't mean a Batch script exacty, but that is certainly an option. In fact, it's perfect for handling lots of PDFs at one time.

What I was refering too is a little different. From a folder level JavaScript, you can create a toolbar or menu item in Acrobat. This toolbar or menu item runs a script that operates on the current PDF. You could think of it as a way to create Macros in Acrobat.

The toolbar button or menu items is for operating on one PDF at a time and the batch script is for operating on multiple PDFs. But that doesn't mean you can't have the best of both worlds. I usually create the toolbar button script first, to validate the idea. I'll put all of the functionality in to a function that's written in a general enough way to also work for a batch script. Then I'll write a batch script that just calls the function.

This approach gives you the ability to easily modify single PDFs, or an entire folder.

Thom Parker
WindJack Solutions
The source for PDF Scripting Info
pdfscripting.com

The Acrobat JavaScript Reference, Use it Early and Often
http://www.adobe.com/devnet/acrobat/javascript.html
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Report

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
Community Beginner ,
Jan 10, 2009 Jan 10, 2009

Copy link to clipboard

Copied

Thanks for explaining your idea. I'll try it your with a button, using your tutorial, then see if I can get it working in a batch.
-Tom

Votes

Translate

Report

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 ,
Mar 09, 2009 Mar 09, 2009

Copy link to clipboard

Copied

I have a slightly simpler situation, but my JS experience is very light.

I have Adobe Pro 7; modifying a .pdf I got from a health ins. web site. I have added several fields to make submitting this form more useable. I would like to print the "date printed" on the form. I have added a text field and don't see anything in the Properties of this field where I can grab the system date value, although I control the format for entering a date manually using the Format tab.

Is there a simple set of code I can paste into the Calculate tab, either in the Simplified field notation box or Custom calculation script, that will value this field automatically?

Thanks in advance. This is a long way from APL, COBOL, Fortran, etc.
RA

Votes

Translate

Report

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
Community Expert ,
Mar 09, 2009 Mar 09, 2009

Copy link to clipboard

Copied

You could place a script in the WillPrint event to place the current date and time in a file.

something like this (for a field named "PrintDate"):

this.getField("PrintDate").value = util.printd("ddd mmm d, yyyy hh:MMtt",new Date());

Thom Parker
WindJack Solutions
The source for PDF Scripting Info
pdfscripting.com

The Acrobat JavaScript Reference, Use it Early and Often
http://www.adobe.com/devnet/acrobat/javascript.html
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Report

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
Community Expert ,
Mar 10, 2009 Mar 10, 2009

Copy link to clipboard

Copied

There is also the Acrobat Scripting Forum http://www.adobeforums.com/webx?13@@.3bbedaa6

Votes

Translate

Report

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 ,
Apr 02, 2009 Apr 02, 2009

Copy link to clipboard

Copied

I apply aboved #109 javascript on Acrobat 9 Pro Extended.
It is fine to print date. BUT when I lock the file with password in menu (Encrypt with Password --> Security ---> Advanced menu), printed date is always same and never changed.
What was the problem in this case???
Is there any solution???
Please Help!!

Votes

Translate

Report

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