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

getPageNthWord to find words with multiple hyphens

kdobos
Registered: Feb 5 2008
Posts: 18
Answered

I am using an Acrobat Pro V8.1 javascript batch to try to find and link words that contain hyphens. The getPageNthWord with bStrip false only returns a series of words. How can I get something to return a string like "1C-130H-2-70JG-00-1" as a single word instead of words, 1C-; 130H-;2-;70JG-;00-;1?

My Product Information:
Acrobat Pro 8.1.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can't, you have to concatonate them together. This is not a trivial script and there are several more complex ways to make sure the words are all in the same line and next to each other, but I'll show you a very simple one.

The code below adds words together when all of the words in a sequence end with a hyphen.
var nWrds = this.getPageNumWords(this.pageNum);var bCollecting = false;var cTheWord = "";var allTheWords = new Array();var rgFindH  = /\-$/;for(var i=0;i<nWrds;i++){var cWrd = this.getPageNthWord(this.pageNum,i,false);var bHasHyphen = rgFindH.test(cWrd);if(!bCollecting){if(bHasHyphen){cTheWord = cWrd;bCollecting = true;}}else{cTheWord += cWrd;if(!bHasHyphen){bCollecting = false;allTheWords.push(cTheWord);}}}

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

kdobos
Registered: Feb 5 2008
Posts: 18
Thom,

excellent! I just might be able to work this into exactly what I need. I figured this task would involve some crafty technique, and I thank you very much for your assistance.
msstrend
Registered: Mar 15 2007
Posts: 53
Is it possible to link the whole word to a web page using the same method?
For example the the text is like below
http://www.thefreedictionary.com/acrobat
http://www.google.co.in/

Please help.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Why yes, you can acquire the coordinates of text, and there is a PDF Link Annotation that can be created and placed with JavaScript. Take a look at Example 2, for the "doc.addLink()" function in the Acrobat JavaScript Reference.

But this is not an easy coding task and it's also a different topic. Please post new topics to a new thread.

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