This is my first time using Actions in Adobe Pro. I would like to..
- Remove all pages in a PDF that contain any of the following strings (Total, Word Document, Excel Spreadsheet) for a PDF in Adobe Pro.
- Remove common strings (CSI, Export, Import) from all pages throughout the PDF.
The following code was found online and addresses #1 but extracts pages based on 1 string, I was not able to get it to work and I would also prefer to run through multiple strings and delete the pages.
JavaScript
x
66
66
1
// Iterates over all pages and find a given string and extracts all
2
3
// pages on which that string is found to a new file.
4
5
6
7
var pageArray = [];
8
9
10
11
var stringToSearchFor = "Total";
12
13
14
15
for (var p = 0; p < this.numPages; p++) {
16
17
// iterate over all words
18
19
for (var n = 0; n < this.getPageNumWords(p); n++) {
20
21
if (this.getPageNthWord(p, n) == stringToSearchFor) {
22
23
pageArray.push(p);
24
25
break;
26
27
}
28
29
}
30
31
}
32
33
34
35
if (pageArray.length > 0) {
36
37
// extract all pages that contain the string into a new document
38
39
var d = app.newDoc(); // this will add a blank page - we need to remove that once we are done
40
41
for (var n = 0; n < pageArray.length; n++) {
42
43
d.insertPages( {
44
45
nPage: d.numPages-1,
46
47
cPath: this.path,
48
49
nStart: pageArray[n],
50
51
nEnd: pageArray[n],
52
53
} );
54
55
}
56
57
58
59
// remove the first page
60
61
d.deletePages(0);
62
63
64
65
}
66
Advertisement
Answer
- One word and two word phrase options.
one-word:
JavaScript
1
10
10
1
for (var p=this.numPages-1; p>=0; p--) {
2
if (this.numPages==1) break;
3
for (var n=0; n<this.getPageNumWords(p)-1; n++) {
4
if (this.getPageNthWord(p, n) == "one-word") {
5
this.deletePages(p);
6
break;
7
}
8
}
9
}
10
two-word:
JavaScript
1
10
10
1
for (var p=this.numPages-1; p>=0; p--) {
2
if (this.numPages==1) break;
3
for (var n=0; n<this.getPageNumWords(p)-1; n++) {
4
if (this.getPageNthWord(p, n) == "1st-word" && this.getPageNthWord(p, n+1) == "2nd-word") {
5
this.deletePages(p);
6
break;
7
}
8
}
9
}
10
- Within Adobe XI Pro, Tools–> Protection–>Search & Remove Text