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

Javascript batch searching and annotating

Fusweb
Registered: Sep 22 2007
Posts: 6

I have a large upcoming project where I have to search and replace a telephone number in over 1000 large pdf documents.
 
I have found a script that I would like to adapt in the Acrobat JS Guide - It highlights misspelt words with a squiggly:
 
/* Mark misspelled words with squiggle */
var chWord, numWords;
for (var i = 0; i < this.numPages; i++)
{
numWords = this.getPageNumWords(i);
for (var j = 0; j < numWords; j++) {
ckWord = spell.checkWord(this.getPageNthWord(i,j))
if (ckWord != null) {
this.addAnnot({
page: i,
type: "Squiggly",
quads: this.getPageNthWordQuads(i,j),
author: "A.C.Acrobat",
contents: ckWord.toString()
});
}
}
}
 
I have replaced the section that spellchecks the word with a specific lookup (for the telephone no code that is changing:
 
/* Mark misspelled words with squiggle */
var chWord, numWords;
for (var i = 0; i < this.numPages; i++)
{
numWords = this.getPageNumWords(i);
for (var j = 0; j < numWords; j++) {
 
if ((this.getPageNthWord(i,j))=="0800") {
this.addAnnot({
page: i,
type: "Squiggly",
quads: this.getPageNthWordQuads(i,j),
author: "A.C.Acrobat",
contents: ckWord.toString()
});
}
}
}
 
This code does not work (I have tried numerous options over the last few weeks) but I cannot for the life of me work out why not. Any pointers please would be most appreciated.

My Product Information:
Acrobat Pro 6.0.5, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The code works fine for me. It adds a "Squiggly" annotation at the specified point.

You state that you need to replace the phone number. Since the phone number is part of the page content it cannot be changed with Acrobat JavaScript. About the best you can do with the PDF is mark the numbers that need changing. The actual changes need to be made in the original documemnt, then reconverted to PDF.

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