2017-06-20 22 views
1

这是我第一次在Adobe Pro中使用Actions。我想..如何使用Adobe XI Pro基于PDF中的短语删除页面?

  1. 删除PDF中包含任何以下字符串 (总计,Word文档,Excel电子表格)的在Adobe Pro的PDF文件的所有页面。
  2. 从整个PDF中的所有页面中删除常用字符串(CSI,导出,导入)。

以下代码在线和地址#1中找到,但是基于1个字符串提取页面,我无法使其工作,我还希望运行多个字符串并删除页面。

// 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 = "Total"; 



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); 



} 

回答

1
  1. 一个字,两个字的词组选择。

一个字:

for (var p=this.numPages-1; p>=0; p--) { 
    if (this.numPages==1) break; 
    for (var n=0; n<this.getPageNumWords(p)-1; n++) { 
     if (this.getPageNthWord(p, n) == "one-word") { 
      this.deletePages(p); 
      break; 
     } 
    } 
} 

双字:

for (var p=this.numPages-1; p>=0; p--) { 
    if (this.numPages==1) break; 
    for (var n=0; n<this.getPageNumWords(p)-1; n++) { 
     if (this.getPageNthWord(p, n) == "1st-word" && this.getPageNthWord(p, n+1) == "2nd-word") { 
      this.deletePages(p); 
      break; 
     } 
    } 
} 
  • 在Adobe XI Pro中,工具 - >保护 - >搜索&删除文本
  • +0

    这个工作时,我创建了一个自定义操作与此代码作为JavaScript,但它在从控制台运行(Ctrl + J)之前一直工作,直到我删除了所有换行符。 – ChrisB

    相关问题