Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
I'm the developer of the free abracadabraTools (not abacadabra tools), you just gave me an idea for the next version.
Thank you.
Copy link to clipboard
Copied
Glad to hear it... I look forward to that 🙂
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Brilliant - that's both elegant and effective... can the jscript generate the field, annotation or watermark automatically?
Copy link to clipboard
Copied
Yes, it can, by using the addField, addAnnot and addWatermarkFromText methods, respectively.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Thank you so much @try67 that works a charm!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more