我正在创建一个将 pdf 解析为文本的服务。当我有该文本时,我必须匹配一组单词。每次匹配时,它都会增加一个计数器。到目前为止,一切都很好。困难在于,在解析为文本时,我无法检查我在 pdf 的哪一页。我已经意识到,在拆分中,每次出现两个连续的换行符(/n/n)就意味着发生了换页。
我想做的是检查页面是否已更改,并且除了计算一个单词总共被找到的次数外,还要说出它在哪些页面上。
例子
let data = `resignations / resignations. adm. mancom .: berenguer llinares
appointments. adm. unique: calvo valenzuela. other concepts: change of the administrative body:
joint administrators to sole administrator. change of registered office. ptda colomer, 6
Official Gazette of the Commercial Registry
no. 182 Friday, September 18, 2020 p. 33755
cve: borme-a-2020-182-03 verifiable in
sarria). registry data. t 2257, f 100, s 8, h a 54815, i / a 4 (10.09.20) .`
let wordsToSearch = ['resignations', "administrators"]
wordsToSearch.forEach((word) => {
// inside of here would like to have track of the page as well
let stringArray = data.split(' ');
let count = 0;
let result = ""
for (var i = 0; i < stringArray.length; i++) {
let wordText = stringArray[i];
if (new RegExp(word).test(wordText)) {
count++
}
}
// the expected result would word has appeared count times in the pages etc
result += `${word} has appeared ${count} times\n`
console.log(result)
/*
resignations has appeared 2 times
administrators has appeared 1 times
*/
})
如果有人也想出另一种方法,那就太好了