提问人:Lee N 提问时间:9/22/2023 最后编辑:JornLee N 更新时间:9/22/2023 访问量:48
在 javascript 控制台中执行 pdf 文件的字符计数?
Performing character count of a pdf file in javascript console?
问:
我想使用 Javascript 控制台在 pdf x-change 编辑器中对我的 pdf 文件进行字符计数,所以基本上我需要一个 Javascript 代码来计算文档的字符数。
目前,我可以使用此代码计算单词。
`/* Count the number of words in the document */
var cnt = 0;
for (var p = 0; p < this.numPages; p++) cnt += getPageNumWords(p);
app.alert("There are " + cnt + " words in this file.");`
现在我想计算字符数。
提前感谢您的帮助!
答:
1赞
coderNinja07
9/22/2023
#1
要在 PDF-XChange Editor 中使用 JavaScript 对 PDF 文档中的字符进行计数,您可以稍微修改现有代码以遍历页面,提取每个页面的文本内容,然后计算字符数。下面是用于计算字符数的代码的修改版本:
/* Count number of characters in document */
var charCount = 0;
for (var pageNum = 0; pageNum < this.numPages; pageNum++) {
var page = this.getPageNumWords(pageNum);
for (var wordNum = 0; wordNum < page.length; wordNum++) {
var word = page[wordNum];
charCount += word.length;
}
}
app.alert("There are " + charCount + " characters in this file.");
此代码将遍历每一页,提取单词,并计算每个单词中的字符数,从而汇总整个文档的字符数。然后,它将在警报对话框中显示总字符数。
评论
0赞
Lee N
9/22/2023
A等待时间过长,代码没有响应。试过很多次:(
评论
getPageNumWords