我需要从带有匹配字符串的 PDF 文档中提取页面,即 Acrobat 创建一个包含所有页面的新文件,它可以在其中找到我在 CSV 或 xlsx 文件中的字符串
This is a sample PDF file 从中我只需要具有以下两个字符串的页面...
我在谷歌搜索时发现了以下代码,但它只搜索一个字符串并创建一个与该字符串匹配的页面的新文件。虽然我需要搜索多个字符串并且只需要一个文件。任何想法请...
// Iterates over all pages and find a given string and extracts all
// pages on which that string is found to a new file.
var pageArray = [];
var stringToSearchFor = "Test";
for (var p = 0; p < this.numPages; p++) {
// iterate over all words
for (var n = 0; n < this.getPageNumWords(p); n++) {
if (this.getPageNthWord(p, n) == stringToSearchFor) {
pageArray.push(p);
break;
}
}
}
if (pageArray.length > 0) {
// extract all pages that contain the string into a new document
var d = app.newDoc(); // this will add a blank page - we need to remove that once we are done
for (var n = 0; n < pageArray.length; n++) {
d.insertPages( {
nPage: d.numPages-1,
cPath: this.path,
nStart: pageArray[n],
nEnd: pageArray[n],
} );
}
// remove the first page
d.deletePages(0);
}
我假设将添加一些代码来加载 CSV/XLSX 文件和一个 FOR/WHILE 循环来搜索该 PDF 文件中的所有字符串并存储它们的页码,然后创建一个包含所有这些页码的新文件。>
答案 0 :(得分:0)
我找到了这个问题的解决方案 here。在本网站中,I downloaded this Adobe Action file 执行我上面描述的操作。它做了一件额外的事情,即突出显示它在文件中找到的不打扰我的文本。