These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Batch process to add Java Script to Will Print

asprague
Registered: Sep 10 2009
Posts: 6
Answered

I am using Acrobat Professional 8.1.6
I have approximatly 492 pdf files already created. These are old paper documents that have been scanned. No Forms or form fields.

I have included the following in the Will Print function for a single pdf and it works great.

The question I have is if there is a way to automate getting this code in the will print function in the already created 400+ pdf's so that I do not have to do it 1 by 1?

var sPrintText = "Printed on " + util.printd("mmm dd, yyyy", new Date()) + " at " + util.printd("HH:MM",new Date());
this.addWatermarkFromText({cText: sPrintText, nFontSize: 12, bOnScreen: false, bOnPrint: true, nTextAlign: 2, nHorizAlign: 2, nVertAlign: 0, nHorizValue: -52, nVertValue: +375 });

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Will any of your users be using Reader?

If so Reader can not add a water mark.

Also, those users with Acrobat should not save the PDF after printing as the water mark will become part of the PDF.

You could use a form field, print but not visible, to hold the data and update the value of the field through the 'willPrint' action.

In batch processing one can use the 'setAction()' method.

// Add WillPrint script// set the text for the willPrint JS script actionvar myWillPrintScript = 'var sPrintText = \"Printed on \" + util.printd(\"mmm dd, yyyy\", new Date()) + \" at \" + util.printd(\"HH:MM\",new Date());\\n'myWillPrintScript += 'this.addWatermarkFromText({cText: sPrintText, nFontSize: 12, bOnScreen: false, bOnPrint: true, nTextAlign: 2, nHorizAlign: 2, nVertAlign: 0, nHorizValue: -52, nVertValue: +375 });\\n'// set the WillPrint actionthis.setAction({cTrigger: "WillSave", cScript: myWillPrintScript});

George Kaiser

asprague
Registered: Sep 10 2009
Posts: 6
Thank You.

Yes - most people will use reader to view and print the documents.

I will try the form field approach.
However, the next question is - is there is a way to automate adding a form field to these 400+ pdf's? I also trust that the code you previously provided will need to be modified. As I am a novice at this code any help is appreaciated.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Yes, it's possible to add a form field with a script. Look at the Document object, addField() method in the reference files.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

asprague
Registered: Sep 10 2009
Posts: 6
Thank you all for the input. From this I have created a batch process to add a form field that will print the date at 90 degress. However, it will only print 90 degrees on the first page. It does add the field to every page however only rotates it on the first page

Can anyone explain what I need to do to rotate this on every page? The script is as follows:


for (var i = 0; i < this.numPages; i++)
{
var fd = this.addField("MyDate", "text", i, [25,108,41,360]);
fd.rotation = 90;
fd.textSize=10;
fd.textFont = font.TimesBI;
fd.allignment = "left";
fd.fillColor = color.transparent;
fd.textColor = color.black;
fd.readonly = true;
fd.print = true;
fd.display = display.noView;
}


// add WillPrint script to populate the form field
this.setAction({cTrigger: "WillPrint", cScript: "var fld = this.getField(\"MyDate\"); fld.value = \"Document Printed on \" + util.printd(\"dd-mmm-yyyy, h:MM tt\",new Date()); \r"});



Also, is the a script that will delete this field "MyDate" on every page of a multiple page document for a given pdf document?