Salir
  • Comunidad global
    • Idioma:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

Why getPageNthWordQuads sometimes return nothing?

Aficionado ,
Jan 30, 2018 Jan 30, 2018

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?

TEMAS
Acrobat SDK y JavaScript
2.6K
Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines

correct answers 1 respuesta correcta

Community Expert , Jan 30, 2018 Jan 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.

Traducir
Community Expert ,
Jan 30, 2018 Jan 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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 30, 2018 Jan 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 30, 2018 Jan 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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 30, 2018 Jan 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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Aficionado ,
Jan 31, 2018 Jan 31, 2018

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" );

            }

    }

}

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 31, 2018 Jan 31, 2018

After:

var ckWord = this.getPageNthWord(p, i, true);

add this:

console.println("Word: '" + ckWord + "'");

Then you can see all found words.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 31, 2018 Jan 31, 2018

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."...

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Aficionado ,
Jan 31, 2018 Jan 31, 2018

Thank you.

ckWord  only return P, it not return "P."

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 31, 2018 Jan 31, 2018

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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Aficionado ,
Jan 31, 2018 Jan 31, 2018

thank you, i changed to: var ckWord = this.getPageNthWord(p, i, false);

It is ok.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Aficionado ,
Jan 31, 2018 Jan 31, 2018

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" );?

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 31, 2018 Jan 31, 2018

this.pageNum accepts only numbers. In a 20 page document you can use 0, 1, ... , 19.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Aficionado ,
Jan 31, 2018 Jan 31, 2018

Can't set a location on Page?

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 31, 2018 Jan 31, 2018

Not with pageNum.

To do that you can use the scroll method, or to set the viewState property.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Jan 31, 2018 Jan 31, 2018

Try debugging your script from the Acrobat Console window, you'll get a lot farther faster.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Aficionado ,
Feb 01, 2018 Feb 01, 2018

How can get Page Index of Page?

Page1.png

Page2.png

If i setl.setAction("this.pageNum = 70" );  it will link to Page o-70 ( 70/1604).

How can get Page index =158, if i input Page=70?

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Feb 01, 2018 Feb 01, 2018
MÁS RECIENTES

You must use the physical page number, not the label.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines