Skip to main content
JR Boulay
Community Expert
Community Expert
December 10, 2021
Answered

JavaScript to detect scanned PDFs and ISO Standards

  • December 10, 2021
  • 1 reply
  • 1051 views

Hi

 

I'd like to know if I can use JavaScript to detect if a PDF conforms to any ISO Standard (PDF/X, PDF/E, PDF/A mainly) and also to detect if it's a "scanned PDF" or not.

 

I  know that I can use a Preflight profile to detect if a PDF not conforms to an ISO Standard, but I need to detect if a PDF conforms to an ISO Standard.

 

Thank you

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer try67

No, JavaScript has no such option, beyond running a Preflight profile on the file.

You can check if it contains any "real" text, though. If not, it's likely (although not necessarily) a scanned document.

To do that you can run the following script:

 

var fileHasText = false;
for (var p=0; p<this.numPages; p++) {
	var numWords = this.getPageNumWords(p);
	if (numWords>0) {
		fileHasText = true;
		break;
	}
}
if (fileHasText) app.alert("There is text in this file.",3);
else app.alert("There's NO text in this file.",3);

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 10, 2021

No, JavaScript has no such option, beyond running a Preflight profile on the file.

You can check if it contains any "real" text, though. If not, it's likely (although not necessarily) a scanned document.

To do that you can run the following script:

 

var fileHasText = false;
for (var p=0; p<this.numPages; p++) {
	var numWords = this.getPageNumWords(p);
	if (numWords>0) {
		fileHasText = true;
		break;
	}
}
if (fileHasText) app.alert("There is text in this file.",3);
else app.alert("There's NO text in this file.",3);