Skip to main content
daitranthanhoa
Inspiring
January 30, 2018
Answered

Why getPageNthWordQuads sometimes return nothing?

  • January 30, 2018
  • 2 replies
  • 2833 views

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?

This topic has been closed for replies.
Correct answer try67

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.

2 replies

Thom Parker
Community Expert
Community Expert
January 30, 2018

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.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Joel Geraci
Community Expert
Community Expert
January 30, 2018

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.

try67
Community Expert
Community Expert
January 30, 2018

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 30, 2018

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.