Answers / JavaScript
Links are set by addlink() batch process. I wish to get text on which rectangular link field are placed.Is it possible? If so how can I get?
Mehedee Rahman 444 days ago
Yes it is possible, but it requires writing a script. The script has to loop through all the words on the page, looking for a match between the link rectangle and the bounding box of the text. Look up the "doc.getPageNthWord" and "doc.getPageNthWordQuads" functions in the Acrobat JavaScript Reference.Thom ParkerThe source for PDF Scripting Info pdfscripting.comThe Acrobat JavaScript Reference, Use it Early and OftenThe most important JavaScript Development tool in AcrobatThe Console Window (Video tutorial)The Console Window(article)Having trouble, Why Doesn't my Script Work
1st thanks to Thom and Kaiser. I have read a lot of solution thread of you. Thais is the first time getting chance to thank. Actually at first I set following script to open corresponding pdf file. Working fine for single file but not for variable. If text of link is 1, 1.pdf file will be linked. If text of link is 2, 1.pdf file will be linked. for (var p = 0; p < this.numPages; p++) { var numWords = this.getPageNumWords(p); for (var i=0; i<numWords; i++) { var ckWord = this.getPageNthWord(p, i, true); for(var a = 0; a< 500; a++) { if ( ckWord == a) { var q = this.getPageNthWordQuads(p, i); // Convert quads in default user space to rotated // User space used by Links. m = (new Matrix2D).fromRotated(this,p); mInv = m.invert() r = mInv.transform(q) r=r.toString() r = r.split(","); l = addLink(p, [r[4], r[5], r[2], r[3]]); l.borderColor = color.red l.borderWidth = 1 var mpath = "/C/Users/Dream_peak/Desktop/+a+".pdf"; var b = app.openDoc(mpath); l.setAction(b); } } } } No change in setAction. I think need another parameter. In this case what should I do?
Mehedee Rahman Commented 444 days ago | Report
Now I think looping conditional script is posted through setAction. Just like this under link action: for(var a = 0; a< 500; a++) { if (event.getPageNthWord == a) { var mpath = "/C/Users/Dream_peak/Desktop/"+a+".pdf"; app.openDoc(mpath) } } I am unable to set perfect coding. Would you help me.
The input to "setAction" is a string of JS code.You're code actually opens the PDF. Do this: var b = "app.openDoc(\"/C/Users/Dream_peak/Desktop/"+a+".pdf\");" l.setAction(b);
Thom Parker Commented 444 days ago | Report
Awesome!!! I am really happy to express thank to you. Your tutorial is great.
Excellent! then please mark this one as answered.
another problem is arisen. When I set for(var a = 5002002; a< 8999999; a++) it is taking more time to finish, even I cannot get output, it is showing "Not responding" but when I use less number, it is working fine. What should I do?
Mehedee Rahman Commented 443 days ago | Report
I have also tested on another file. Working fine. However in main file no result. Would you tell me there is any problem in this file for searching certain number. https://acrobat.com/#d=GXpbvcTHXW9bd6xvCwZ-wA
Sorry for frequently Asking. Above issue solved. Taking more time during Executing. Another issue: If I want to set relevant path what should I do. I was trying but getting error. var b = "app.openDoc(\a+".pdf\",this);" l.setAction(b);
Read this, and start posting to a new thread http://acrobatusers.com/tutorials/js_exception_handling
Thom Parker Commented 443 days ago | Report
Nice! I have posted a new thread named "How to reduce executing time". Would you review that? Thanks
Mehedee Rahman Commented 442 days ago | Report
Not easily. You would have to get the location of the link's quads and then look for words that fall within those quads.
Download Acrobat XI trial
Get the trial now
How do I change colors of objects in Acrobat Pro?
Asked by David Evert · no replies
how do i rotate one page in a combined document?
Asked by Peter Schuerch · no replies
Flow text from one text field to the next text field
Asked by Kathy Holtz · no replies
Export/Save form data to xls, csv or txt file
Asked by Brad Herbert · no replies
acrobat x pro distorts screen text
Asked by Richard Sapp · no replies
Translating a pdf from polish to english
Asked by Elvia Rios · 1 answer
Edit my profile
Get a Widget
Rewards
Last 30 Days