Copy link to clipboard
Copied
I using Acrobat COM:
I want get Coordinates of Words.
iPage = 56
Dim PdfPage = oDoc.AcquirePage(iPage)
Dim PageHL = CreateObject("AcroExch.HiliteList") '// created to get the page text
Dim PageHLRes = PageHL.Add(0, 9000) '<<--SET in FILE! (Start,END[9000=All])
Dim PageSel = PdfPage.CreatePageHilite(PageHL)
For i = 0 To PageSel.Getnumtext - 1 '// start the word loop on current page
Dim word = PageSel.getText(i) '// get one word
If word.ToString.Contains("P") Then
Dim q = jso.getPageNthWordQuads(iPage, i)
End if
next
But some case jso.getPageNthWordQuads return nothing.
Why? exist other way to get Coordinates of Words?
I would recommend you do it all in JS, instead of a mix of JS and VBA.
And no, that's the only way of doing it using JS.
Copy link to clipboard
Copied
I would recommend you do it all in JS, instead of a mix of JS and VBA.
And no, that's the only way of doing it using JS.
Copy link to clipboard
Copied
Try67 is correct, for something so complex this should be done in a JavaScript function, which is called from the VB.
Even if you keep it all in VB you can't say anything about what is returned until you've tested the same loop in the Acrobat JS Console window. It could be a timing problem, The JSO just isn't keeping up with the loop, so it returns nothing. It could also be that what JS thinks is the number of words on a page is different from what your PageSel object thinks. This is much more likely. If you are going to do something in JS, it needs to be completely in JS. Mixing platforms is always a bad idea.
Copy link to clipboard
Copied
I've also found that the delayed plugin loading in Acrobat will cause race conditions where you can invoke the JSO but the JavaScript engine isn't ready in Acrobat yet. Before trying to use the JSO, put in an interval that checks for the existence of the method you want to use. After you can confirm it's existence, then send Acrobat the entire JavaScript function you need to define and only then call it to run.
Copy link to clipboard
Copied
Another issue could be that VBA's getText method doesn't work exactly the same as the JS getPageNthWord and getPageNthWordQuads methods, so even if it's all working correctly you would still get incorrect results because the index numbers returned by getText won't match those used by the JS methods.
Copy link to clipboard
Copied
I try convert to JS and call ExecuteThisJavascript:
But it not working. Can you help me?
My Script add link to Text:
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);
if ( ckWord == "P.")
{
var q = this.getPageNthWordQuads(p, i);
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;
l.setAction("this.pageNum = 1" );
}
}
}
Copy link to clipboard
Copied
After:
var ckWord = this.getPageNthWord(p, i, true);
add this:
console.println("Word: '" + ckWord + "'");
Then you can see all found words.
Copy link to clipboard
Copied
If you specify the bStrip parameter of getPageNthWord as true it's impossible for the return value to end with a period, as that parameter means it will be stripped. Change it to false and then add a command to print it out, as Bernd suggested. It's also possible there will be a space after it, so you have to take that into consideration as well.
Either that or leave it as true and remove the period from "P."...
Copy link to clipboard
Copied
Thank you.
ckWord only return P, it not return "P."
Copy link to clipboard
Copied
As I wrote, you need to change the bStrip parameter from true to false for it to return any trailing white-spaces and punctuation marks.
Copy link to clipboard
Copied
thank you, i changed to: var ckWord = this.getPageNthWord(p, i, false);
It is ok.
Copy link to clipboard
Copied
i'm sorry.
I can set Link to Text in a Page?
Ex: l.setAction("this.pageNum = 1" );
==> l.setAction("this.pageNum = 1 NO.20" );?
Copy link to clipboard
Copied
this.pageNum accepts only numbers. In a 20 page document you can use 0, 1, ... , 19.
Copy link to clipboard
Copied
Can't set a location on Page?
Copy link to clipboard
Copied
Not with pageNum.
To do that you can use the scroll method, or to set the viewState property.
Copy link to clipboard
Copied
Try debugging your script from the Acrobat Console window, you'll get a lot farther faster.
Copy link to clipboard
Copied
How can get Page Index of Page?
If i set : l.setAction("this.pageNum = 70" ); it will link to Page o-70 ( 70/1604).
How can get Page index =158, if i input Page=70?
Copy link to clipboard
Copied
You must use the physical page number, not the label.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now