Copy link to clipboard
Copied
I have no experience writing java, I'm in need of a function that will auto detect and delete blank pages in large documents. I have yet to find any other way to automate this.
Thanks!
Copy link to clipboard
Copied
Java and JavaScript are not the same thing... Only the latter can be used within Acrobat, and it can only detect if a page has no text (or objects such as fields, links, comments, etc.) on it, not things like images or graphics. If that's alright with you then it can be done using a fairly simple script.
Copy link to clipboard
Copied
Sorry, I didn't realize they were different, but yes that's what I need. Do you have a script I can use?
Thank you!
Copy link to clipboard
Copied
What version of Acrobat do you have?
Copy link to clipboard
Copied
Adobe Acrobat DC 19.010.20069
Copy link to clipboard
Copied
The number of words on a page is provided by the function "this.getPageNumWords()".
But there is another way. A truly blank page will have an empty bounding box. The "this.getPageBox("BBox") will return a rectangle with zero area.
However, for detecting blank pages both of these methods are seriously flawed. Automatically generated documents will often have headers and footers that should not be counted, and OCR on scanned documents will often mark image artifacts as characters or content.
Copy link to clipboard
Copied
Also, a simple scanned document contains a large image, even on blank pages, so the bounding box test cannot be used (nor any other test). Scanning also adds another complication even if writing a plug-in (very advanced!) since the scanned "blank" sheet is never simply white pixels.
In essence, banapol, I recommend you give up the idea.
Copy link to clipboard
Copied
Despite all the correct comments provided above, if you still want to do it based only on the number of words on a page, you can use this code:
for (var p=this.numPages-1; p>=0; p--) {
var numWords = this.getPageNumWords(p);
if (numWords==0) {
if (this.numPages==1) {
app.alert("Error! Can't delete the last page of the file.");
} else this.deletePages(p,p);
}
}