Copiar vínculo al Portapapeles
Copiado
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.
Copiar vínculo al Portapapeles
Copiado
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.
Copiar vínculo al Portapapeles
Copiado
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.
Copiar vínculo al Portapapeles
Copiado
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.
Copiar vínculo al Portapapeles
Copiado
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.
Copiar vínculo al Portapapeles
Copiado
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" );
}
}
}
Copiar vínculo al Portapapeles
Copiado
After:
var ckWord = this.getPageNthWord(p, i, true);
add this:
console.println("Word: '" + ckWord + "'");
Then you can see all found words.
Copiar vínculo al Portapapeles
Copiado
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."...
Copiar vínculo al Portapapeles
Copiado
Thank you.
ckWord only return P, it not return "P."
Copiar vínculo al Portapapeles
Copiado
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.
Copiar vínculo al Portapapeles
Copiado
thank you, i changed to: var ckWord = this.getPageNthWord(p, i, false);
It is ok.
Copiar vínculo al Portapapeles
Copiado
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" );?
Copiar vínculo al Portapapeles
Copiado
this.pageNum accepts only numbers. In a 20 page document you can use 0, 1, ... , 19.
Copiar vínculo al Portapapeles
Copiado
Can't set a location on Page?
Copiar vínculo al Portapapeles
Copiado
Not with pageNum.
To do that you can use the scroll method, or to set the viewState property.
Copiar vínculo al Portapapeles
Copiado
Try debugging your script from the Acrobat Console window, you'll get a lot farther faster.
Copiar vínculo al Portapapeles
Copiado
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?
Copiar vínculo al Portapapeles
Copiado
You must use the physical page number, not the label.
Encuentra más inspiración, eventos y recursos en la nueva comunidad de Adobe
Explorar ahora