javascript - 基于 Acrobat Pro DC Java Script 中的匹配字符串提取页面
问题描述
我需要从具有匹配字符串的 PDF 文档中提取页面,即 Acrobat 创建一个包含所有页面的新文件,在其中找到我在 CSV 或 xlsx 文件中的字符串
这是一个示例 PDF 文件,我只需要具有以下两个字符串的页面...
- 宏
- 销售员
我在谷歌搜索时发现了以下代码,但它只搜索一个字符串并创建一个与该字符串匹配的新页面文件。虽然我需要搜索多个字符串并且只需要一个文件。有什么想法请...
// 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 文件中的所有字符串并存储它们的页码,然后使用所有这些页码创建一个新文件。
解决方案
推荐阅读
- java - Java 对象数组元素设置为 null
- traefik - 为什么 Traefik 2.2 & Let's Encrypt 不支持新的注解?
- firebase - 活跃的侦听器是每天一次填充 UI 更改的好解决方案吗?
- python - 如何过滤数据框以便在特定时间每天出现一次
- java - 如何在其他项目的 Eclipse 中添加相同的透视图?
- ios - 另一个scrollView中的Xcode 11 scrollView约束问题
- python - Mapbox:以编程方式从 .geojson 文件更新 mapbox 数据集
- android - 如何以编程方式从服务(背景)的任何位置在移动设备(android)上截取屏幕截图?
- python - 为什么 Python "is" 运算符对包含相同字符串的变量给出不同的结果
- javascript - 为什么分配给对象 __proto__ 不起作用?