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

Batch processing with Acrobat 8 Standard?

bwnichols
Registered: Aug 28 2007
Posts: 4

Hello All,
 
I wrote this nifty java code using Acrobat Pro 6 awhile back, which if executed using 'Batch Processing' prompts the user for the files to process, then 1) adds a tag and 2) a scrap of Java code to each selected document which in turn updates the tag on document open, inserting a string equal to filename up to the first space as the tag contents.
 
So once the documents have been processed initially, the filename can be changed and any Acrobat version (even Reader) which calls up the document updates the tag with the current filename string.
 
It works pretty slick, except now we've updated office-wide to Acrobat 8 Standard (my Acrobat 6 Pro officially 'went away' -- don't worry, I still have a copy cached away), but going forward I'd really like ANY user to be able to ADD THE TAGS in the first place, using Acrobat 8 Standard.
 
The code below, as-is, if placed in an Acrobat 8 Standard document and linked to the 'Document Did Save' event, adds the desired tag to the current document. Wundervoll! We're on to something...
 
Could this code be enclosed in a loop, with perhaps a dialog box confirmation, so that when triggered by the 'Document Did Save' event it processed all the pdf files in the host document's current directory? Not as nice as prompting for the files, but for our purposes this would answer adequately.
 
Our IT Dept. is not going to spring for 100 copies of Acrobat Pro, and while two or three copies for key people to do the initial processing is a potential answer, it would be MUCH better if the code could be embedded in template file and executed by anyone using Acrobat 8 Standard.
 
Or perhaps an external JavaSript console could be configured for the purpose? Hmm, sounds like a possibility, but Java isn't really what I do for a living...I could probably fumble through it, if someone could give me an outline of what needs to be done.
 
In summary, how can this code best be run cheaply?
 
Thanks in Advance,
Brandon Nichols
  
/* Add Tag */
 
function AddTag()
{
 
//Remove any existing field named TAG if exist
if (this.getField("TAG") != null)
{
this.removeField("TAG");
}
   
// //Remove all fields (could be damaging -- saved here for ref)
// for(var i = this.numFields - 1; i > -1; i--)
// {
// //Get the field name for field i
// var fieldName = this.getNthFieldName(i);
//
// //Now delete this field from doc
// this.removeField(fieldName);
// }
  
var pp = this.path.replace(/.*\/|\.pdf$/ig, "");
pp = pp.match(/^([A-Za-z0-9\-\,\_\[\]])+(([A-Za-z0-9\-\,\_\[\]])+)*/, "");
 
for (var p=0; p

My Product Information:
Acrobat Standard 8.0999999999999996447286321199499070644378662109375, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
you lost everything after the "Less Than" symbol. Please repost and replace the angle bracket with

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Just use "lt"

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

bwnichols
Registered: Aug 28 2007
Posts: 4
Thanks Thom,

Here's the code, with all left angle brackets (2) replaced by "lt" (including quotes; replace w/ LAB for code to run):

/* Add Tag */

function AddTag()
{

//Remove any existing field named TAG if exist
if (this.getField("TAG") != null)
{
this.removeField("TAG");
}// //Remove all fields (could be damaging -- saved here for ref)
// for(var i = this.numFields - 1; i > -1; i--)
// {
// //Get the field name for field i
// var fieldName = this.getNthFieldName(i);
//
// //Now delete this field from doc
// this.removeField(fieldName);
// }


var pp = this.path.replace(/.*\/|\.pdf$/ig, "");
pp = pp.match(/^([A-Za-z0-9\-\,\_\[\]])+(([A-Za-z0-9\-\,\_\[\]])+)*/, "");

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

//** Aquire the crop box for the current page

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

//** Calculate the crop box size in points
var nWidth = (pageRect[2] - pageRect[0]);
var nHeight = (pageRect[1] - pageRect[3]);

//Add new tag field
frect = new Array();

// 792 pt = 11 in
// 612 pt = 8.5 in
// 72 pt = 1 in
// 18 pt = 0.25 in
frect[0] = nWidth - 18 - 216; // 216 pt = 3 in
frect[1] = nHeight - 18;
frect[2] = nWidth - 18;
frect[3] = nHeight - 18 - 18;


var ff = this.addField("TAG", "text", p, frect );
ff.borderStyle = border.s;
ff.textSize = 12;
ff.alignment = "center";
ff.bgColor = color.white;
ff.borderColor = color.blue;
ff.borderStyle = border.s;
ff.borderWidth = 2;
ff.textColor = color.blue;
ff.textFont = font.Times;
ff.defaultValue = "TAG";
ff.value = pp[0];
ff.display = display.visible;
ff.readonly = true;
}//add document level update script

this.addScript("UpdateTag", function UpdateTag()
{
//Update the field TAG if exist
if (this.getField("TAG") != null)
{
var ff = this.getField("TAG");
var pp = this.path;
pp = pp.replace(/.*\/|\.pdf$/gi, "");
pp = pp.match(/^([A-Za-z0-9\-\,\(\)\_\[\]])+(([A-Za-z0-9\-\,\(\)\_\[\]])+)*/, "");
ff.value = pp[0];
}
else
{

//duplicate code above...

var pp = this.path.replace(/.*\/|\.pdf$/ig, "");
pp = pp.match(/^([A-Za-z0-9\-\,\_\[\]])+(([A-Za-z0-9\-\,\_\[\]])+)*/, "");

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

//** Aquire the crop box for the current page
var pageRect = this.getPageBox({nPage: p });

//** Calculate the crop box size in points
var nWidth = (pageRect[2] - pageRect[0]);
var nHeight = (pageRect[1] - pageRect[3]);

//Add new tag field
frect = new Array();

// 792 pt = 11 in
// 612 pt = 8.5 in
// 72 pt = 1 in
// 18 pt = 0.25 in
frect[0] = nWidth - 18 - 144; // 144 pt = 2 in
frect[1] = nHeight - 18;
frect[2] = nWidth - 18;
frect[3] = nHeight - 18 - 18;


var ff = this.addField("TAG", "text", p, frect );
ff.borderStyle = border.s;
ff.textSize = 12;
ff.alignment = "center";
ff.bgColor = color.white;
ff.borderColor = color.red;
ff.borderStyle = border.s;
ff.borderWidth = 2;
ff.textColor = color.red;
ff.textFont = font.Times;
ff.defaultValue = "TAG";
ff.value = pp[0];
ff.display = display.visible;
ff.readonly = true;
}}
}
)

//note that the list name selected for the execute function
//must sort alphasequentially AFTER the list name of the called function
//else the called function WON'T BE DEFINED when it is called.

this.addScript("UpdateTagExecute", "UpdateTag();")

}
// call function
AddTag();