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

Cumulative word count...

Contributor ,
Dec 10, 2020 Dec 10, 2020

This is step 1 of a much more complex process I'd like to achieve using javascript - unfortunately with no javascript skills whatsoever!

 

What I have at the moment is a javascript plugin (abacadabra tools) which will give me the word count for an individual page (whichever page my cyrsor is on) in a message box... it's a start!

 

I'd like to get a cumulative word count for each page of a document and be able to create text output at the bottom of each page with that number in  it... 

 

Can anyone advise if this is at least theoretically possible?

<br>
~ David Sweeney-Bear ~
TOPICS
JavaScript
1.7K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 11, 2020 Dec 11, 2020

Here you go, it will add a field to the bottom-left corner of each page with the words count:

 

var r = [5, 25, 50, 5];
var counter = 0;
for (var p=0; p<this.numPages; p++) {
	var numWords = this.getPageNumWords(p);
	counter+=numWords;
	//console.println("Number of (total) words on page " + (p+1) + ": " + counter);
	var f = this.addField("PageText"+p, "text", p, r);
	f.readonly = true;
	f.defaultValue = counter;
	f.value = counter;
}

View solution in original post

Translate
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 11, 2020 Dec 11, 2020

I'm the developer of the free abracadabraTools (not abacadabra tools), you just gave me an idea for the next version.

Thank you.


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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 ,
Dec 11, 2020 Dec 11, 2020

Glad to hear it... I look forward to that 🙂

<br>
~ David Sweeney-Bear ~
Translate
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 11, 2020 Dec 11, 2020

Yes, is it, both theoretically and practically.

All you need is a simple counter and a loop, like so:

 

var counter = 0;
for (var p=0; p<this.numPages; p++) {
	var numWords = this.getPageNumWords(p);
	counter+=numWords;
	console.println("Number of (total) words on page " + (p+1) + ": " + counter);
}

 

If you want to add this value to the page itself you can use a field or an annotation, or even a watermark.

Translate
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 ,
Dec 11, 2020 Dec 11, 2020

Brilliant - that's both elegant and effective... can the jscript generate the field, annotation or watermark automatically?

<br>
~ David Sweeney-Bear ~
Translate
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 11, 2020 Dec 11, 2020

Yes, it can, by using the addField, addAnnot and addWatermarkFromText methods, respectively.

Translate
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 ,
Dec 11, 2020 Dec 11, 2020

Sorry to have to ask, but google hasn't helped me... what would be the syntax for getting the addField function to use the "counter" var to add a field on the current page, and where/how would I insert that in the "loop" you defined earlier?

<br>
~ David Sweeney-Bear ~
Translate
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 11, 2020 Dec 11, 2020

Here you go, it will add a field to the bottom-left corner of each page with the words count:

 

var r = [5, 25, 50, 5];
var counter = 0;
for (var p=0; p<this.numPages; p++) {
	var numWords = this.getPageNumWords(p);
	counter+=numWords;
	//console.println("Number of (total) words on page " + (p+1) + ": " + counter);
	var f = this.addField("PageText"+p, "text", p, r);
	f.readonly = true;
	f.defaultValue = counter;
	f.value = counter;
}
Translate
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 ,
Dec 11, 2020 Dec 11, 2020
LATEST

Thank you so much @try67  that works a charm! 

<br>
~ David Sweeney-Bear ~
Translate
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