Adobe PDF Javascript提取名称,保存文件
Adobe PDF Javascript to Extract Name, save file
在Adobe Acrobat Pro XI中查找有关Javascript的帮助。
到目前为止,我拥有的是:
/* Extract pages to file */
// Regular expression used to acquire the base name of file
var re = /'.pdf$/i;
// filename is the base name of the file Acrobat is working on
var filename = this.documentFileName.replace(re,"");
try {for (var i = 0; i < this.numPages; i+=4)
this.extractPages({
nStart: i,
nEnd: i+3,
});
} catch (e) { console.println("Aborted: " + e) }
现在发生的是,它提取页面范围并创建一系列打开的文件,然后我可以重命名这些文件。
我想做的是添加一个循环,从账单中提取一个名称,然后将其用作文件名,在文件夹中创建一个新文件。
我发现了这个:
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;
}
}
}
我想这会让我走到那里,但我不确定如何将其纳入我的循环中。
我想我需要在文档中搜索一个静态字符串(在本例中为"Student Name"),然后返回接下来的两个单词。
使用复制粘贴的代码创建了一个文件来做这类事情(以及Thom Parker在Adobe论坛上的一些帮助,请参阅:https://community.adobe.com/t5/acrobat/step-by-step-instructions-for-saving-a-pdf-in-acrobat-dc-using-a-javascript/m-p/10893916?page=1#M238905)
// https://community.adobe.com/t5/acrobat/how-to-set-up-a-default-value-in-execdialog/td-p/9343585?page=1
var dialogTitle = "Please specify ";
var defaultAnswer = "";
var stringToSearchFor = app.response("Client ID",
dialogTitle, defaultAnswer);
//https://acrobatusers.com/tutorials/print/how-save-pdf-acrobat-javascript/
/* Put script title here */
// 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 = "64718";
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);
// https://community.adobe.com/t5/acrobat/how-to-save-as-pdf-form-using-script/td-p/9848947?page=1
// Split Path into an array so it is easy to work with
var aMyPath = this.path.split("/");
// Remove old file name
aMyPath.pop();
// Add new file name
aMyPath.push(stringToSearchFor);
// Put path back together and save
d.saveAs(aMyPath.join("/")+".pdf");
}
相关文章:
- 在Firefox中自动保存文件
- 提示用户通过AJAX调用保存文件
- 如何提供保存文件而不是从internet explorer打印文件的选项
- Basecamp的Trix WYSIWYG编辑器gem没有在Rails 4应用程序中保存文件附件
- 钛:从Android的相机/图库图像本地保存文件
- 如何使用office.js检查未保存文件的具体文件扩展名
- node-webkit:将数据导出到csv并提示用户保存文件
- 通过本地应用程序的Javascript保存文件
- 如何为使用 JSP 生成的下载文件显示“保存文件”对话框
- 在浏览器中保存文件的Javascript
- 使用数据URI提示用户保存文件
- 如何在使用php使用jquery编辑文件后保存文件
- 如何在Safari中显示保存文件对话框
- Javascript:使用ActiveXobject保存文件
- 强制浏览器在单击链接后保存文件
- 如何在javascript中将事件添加到浏览器的“保存文件”对话框中
- 谷歌浏览器扩展程序在客户端保存文件
- 在文件保护程序.js中保存文件后关闭窗口
- 保存文件选项,用于将html文件保存在系统中的给定位置
- Adobe PDF Javascript提取名称,保存文件