Tuesday, 15 July 2014

Word Count in PDFs using Acrobat Pro

To count words in a pdf file you need to run Acrobat Pro and use the javascript console.

To enable the javascript console, this web site gives a great introduction:


Once you have the console up and running you should copy and paste the following in the console window, then highlight it all and press CTRL-Enter to run it.

var cnt=0;
for (var p = 0; p < this.numPages; p++) cnt += getPageNumWords(p);
app.alert("There are " + cnt + " words in this file.");

The above code will count everything and view symbols as splits in words, which can make for interesting counts for documents containing maths, so another way to do this is to count the number of spaces. To do this use the following code

var cntLetters = 0;
var cntWords = 0;
var cntSpaces = 0;

for (var i = 0; i < this.numPages; i++ ) for (var j = 0; j < this.getPageNumWords(i); j++, cntSpaces++) {
if (this.getPageNthWord(i, j).length > 0) cntWords++;
cntLetters += this.getPageNthWord(i, j).length;}
app.alert('There are ' + cntWords + ' words in this file' );

On completion you will get a window like below

No comments: