Skip to main content
Jo_2013
Known Participant
January 10, 2017
Answered

Get all words on a page and report to the console

  • January 10, 2017
  • 1 reply
  • 557 views

I have a script which finds all words in a pdf and reports these words back to the console in separate lines for each word.

Console report:

TRESTLE

FOOTING

BUILDING

DETAILS

FOR

PROJECT

X

The script needs to be modified to report all words found back to the console in a single line (one sentence) with a space between each word.

If anyone can please provide assistance this will be most appreciated, script as follows:

var ckWord, numWords;

for (var i = 0; i < this.numPages; i++ )

{

numWords = this.getPageNumWords(i);

for (var j = 0; j < numWords; j++)

{

ckWord = this.getPageNthWord(i, j)

if ( ckWord != null )

{

console.println(ckWord);

}

}

}

This topic has been closed for replies.
Correct answer George_Johnson

var i, j, ckWord, numWords, aWords = [];

for (i = 0; i < this.numPages; i++ ) {

    numWords = this.getPageNumWords(i);

    for (j = 0; j < numWords; j++) {

        ckWord = this.getPageNthWord(i, j);

        if (ckWord) {

            aWords.push(ckWord);  // Add word to array

        }

    }

}

// Print the array items, separating each by a space

console.println(aWords.join(" "));

1 reply

George_JohnsonCorrect answer
Inspiring
January 10, 2017

var i, j, ckWord, numWords, aWords = [];

for (i = 0; i < this.numPages; i++ ) {

    numWords = this.getPageNumWords(i);

    for (j = 0; j < numWords; j++) {

        ckWord = this.getPageNthWord(i, j);

        if (ckWord) {

            aWords.push(ckWord);  // Add word to array

        }

    }

}

// Print the array items, separating each by a space

console.println(aWords.join(" "));

Jo_2013
Jo_2013Author
Known Participant
January 10, 2017

Thank you very much George, by using the array and then join with a space the words now report to the console in a sentence. Your help is very much appreciated.