• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

How do I get a word count for a PDF doc or for a selected passage?

Community Beginner ,
May 01, 2015 May 01, 2015

Copy link to clipboard

Copied

How do I get a word count for a PDF doc or for a selected passage?

TOPICS
Create PDFs , How to

Views

73.0K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

I just downloaded and tried this script. I got a more than 20% greater word count than using Word or some other tools.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Word counting is an exact science. Especially in PDF, where there aren't even any words. So the first thing is to use guesswork and spacing to try and decide the likely word breaks.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

did you mean to say "is not an exact science?"

because it absolutely is. Microsoft can do it. Google can do it. A host of other commercial tools can do it, with only nominal varriance in results.

 

And yes, PDFs certainly do contain words. And yes, the spaces between the groups of letters is how we figure out what the words are.

 

What I'd like to know is, what does javascript count as a "word" in Acrobat that other tools don't?

 

I've got a file that's 46,000 words (per Word, AnyCount, Google Docs). Simple javascript code that's suppossed to do the same thing in Acrobat returns 47,000 words. Another that has 991 words in Word returns 1184 words in the console.

 

the javascript, found here on these forums  is:

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

 

It's just terribly frustrating that this basic functionality isn't included. And that any tools to do it natively within the program return such wildly inaccurate results.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Apologies, exactly - "NOT an exact science". 

PDFs do not contain spaces - spaces are the result of guesswork. So they may vary. It's unusual to have such a large variation, nevertheless. If you indeed have Acrobat, which you mention, then just export to Word and let it count. Compare before and after. If you said Acrobat but meant Acrobat Reader, then try a copy/paste to Word of a page of text and compare. As I understand it, copy/paste and JavaScript do the same "word finding".

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

you're going to have to explain that one — "PDFs do not contain spaces" — because they absolutely do. They are characters and you can type them. I can copy them out of one file (the PDF) and paste them into another (Word).

 

this is what I get in the console when I run the script on a simple file:

 

DCardillo_PRH_0-1663255007222.png

1184 words

 

I Select All > Copy, open Word, Paste, run a word count and get:

DCardillo_PRH_1-1663255075571.png

991 words. 5,623 characters with spaces, 4,803 characters without spaces, or approximately 780 spaces.

 

I have people who work on several hundred titles a season, and the seemingly simple step of exporting a docx or rtf file and opening in Word becomes tedious and time consuming when just selecting a menu item or clicking a button (like a script) should be able to do it — reliably — within the application.

 

Back in the old days, when we did this manually, we'd take the total character count and just divide by 5. In my above example, I'd get 1125 — just short of what Acrobat's console is reporting.

 

Acrobat's Search function can return whole words, so it can differentiate between part of a word and a whole word.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 06, 2017 Nov 06, 2017

Copy link to clipboard

Copied

On Windows platform you can use AnyCount PDF Word Count tool​ even without Adobe Acrobat or Adobe Acrobat reader installed.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

for $15/month/user 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

Is it possible to do a word count using Adobe Acrobat DC? if so, how is it done?

Thank you

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2020 Jun 25, 2020

Copy link to clipboard

Copied

Just install the (free) "Word Counter" plugin which is part of the (free) abracadabraTools: https://www.abracadabrapdf.net/?p=972

 

It is also available for Acrobat Reader.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

I tried this word counter. I got an up to 20% greater word count than using MS Word.

 

Some of the other tools look useful — basically one-click solutions to things that are done with Preflights. But if you're experienced enough to know how to use them properly* you likely already have custom preflight to do these things.

 

(* Crop, for example, says it "removes" marks and stuff outside the Trim. If you've ever cropped a PDF before you know it doesn't actually remove these items, just restricts them from view. This is important for people who believe they're removing sensitive data.)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

Highlight your text. Copy/paste it into a wordprocessing program (Google Docs, MS Word, etc) and use that program's word counter tool.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

I have a  multilined field named "Bio" that needs to have the words typed, counted. This field must also not allow the user to type in more then 65 words.  If less than 65 words the field is editable.  At 65 words the field becomes locked or read only. There is also field on the form, named "WordCount." This field will get/display the total words typed in the "Bio" field.

I hope someone can help.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Locking the field is a bad idea. What if the user made a mistake and wants to go back and edit it?

It's better to not allow more than 65 words to be entered by reject any new input when that happens.

To do that you would need to use a custom Keystroke script.

I've developed a similar (paid-for) tool that can count words "live" as the user types them into a field. It wouldn't be too hard to adjust it to also stop the user from entering more than a specific amount of words into it. You can find it here: Custom-made Adobe Scripts: Acrobat -- "Live" Characters and Words Counter

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

Word counts are not the best way to limit input on a field. Instead, set the field to allow multiline input but not to allow scrolling long text. Then set the font size (not auto). Acrobat will then allow the user to enter as much text as fits within the boundaries of the field given the font size and then beep if they enter too much. This allows you to be flexible with word length and number of words while still limiting the amount of text entered.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Thanks for your replies!  However I finally got this thing figures out with scripting!  I place the following code in the document level:

Script Name: wordsMax

The code:

function limit_words_ks(max_words)

{

// Get all of the characters in the field

   var s = AFMergeChange(event);

// Reject if more than max_num words

   if (s.split(/[ ]+/).length > max_words) {

      app.alert("You can't enter more than 65 words to this field.");

      event.rc = false;

   }

}

In the field to be typed in I added the following Javascript into the Custom Key Stroke Script:

The code:

{

    var Bio = event.value.split(" ");

    this.getField("WordCount").value = Bio.length;

    limit_words_ks(65);

}

The result was the word input in the field were totaled in the field "WordCount.", When the user attempted to go past 65 words an alert window popped up telling the user "You can't enter more than 65 words to this field."  The user could remove words, but not add.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

That is a script...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 15, 2017 Dec 15, 2017

Copy link to clipboard

Copied

I have a script, counts words typed into text box and displays it in another box.

But the number of words only show up when you exit the field. I want the numbers to show as you type.... I tried on blur, mouse exit etc.....any ideas how to do it?

Validate / Run custom validation script

var aWords = event.value.split(" ");

this.getField("WordCount").value = aWords.length;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2017 Dec 15, 2017

Copy link to clipboard

Copied

You need to create a custom Keystroke script, as that's the only one that is executed each time you type something into the field.

If you're interested I've already developed a tool that does just that: Custom-made Adobe Scripts: Acrobat -- "Live" Characters and Words Counter

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2017 Dec 15, 2017

Copy link to clipboard

Copied

You'll find scripts for counting words, letters, etc. here:

Calculating field values and more

As Try says, you'll need to use a custom keystroke event. This is tricky because event.value does not include the newly typed text, so you'll need to combine both event.value and event.change.

Here's how:

if(!event.willCommit)

{

  var nChars = event.selEnd - event.selStart;

  var aFull = event.value.split("");

  aFull.splice(event.selStart, nChars, event.change);

  var strFull = aFull.join("");

  var aWrds = strFull.split(/\s+/);

  ... rest of code ...

}

Using the regEx for the split catches multiple spaces, tabs, and line feeds

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2022 Sep 16, 2022

Copy link to clipboard

Copied

"Word counter" is one of my free plugins for Acrobat:

https://www.abracadabrapdf.net/utilitaires/utilities-in-english/abracadabratools_en/

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines