Reputation: 387
I have over 30,000 pdf files. Some files are already OCR and some are not. Is there a way to find out which files are already OCR'd and which pdfs are image only?
It will take for ever if I ran every single file through an OCR processor.
Upvotes: 13
Views: 9577
Reputation: 28198
The following script will recursively find files that need OCR. You'll need to get pdftotext
from your favorite source. I used Cygwin to install it.
#!/bin/bash
find . -name "*.pdf" | while read file; do
if [ -z "$(pdftotext "$file" - | sed 's/\s//g')" ]; then
echo $file
fi
done
I used the following script to move files that need OCR into a subfolder so that I can perform batch OCR from Acrobat. You could instead run OCR directly with the command-line tool of your choice.
#!/bin/bash
mkdir ocr
for file in *.pdf; do
echo $file
if [ -z "$(pdftotext "$file" - | sed 's/\s//g')" ]; then
mv "$file" ocr
fi
done
Upvotes: 0
Reputation: 1
You can scan a folder or entire drive using desktop search tool "dtSearch". At the end of the scan, it will show the list of all "image only" PDFs. In addition, it will also show a list of "encrypted" PDFs if any.
Upvotes: -1
Reputation: 7521
I found that TotalCmd has a plugin that handles this: https://totalcmd.net/plugring/pdfOCR.html
pdfOCR is wdx plugin that discovers how many pages of PDF file in current directory needs character recognition (OCR), i.e. how many pages in PDF file have no searchable text in their layout. This is mostly needed when one is preparing PDF files for one’s documentation or archiving system. Generally in one’s work with PDF files they need to be transformed from scanned version to text searchable form before they are included in any documentation to allow for manual or automatic text search. The pdfOCR plugin for Total Commander fulfils a librarian’s need by presenting the number of pages that are images only with no text contained. The number of scanned pages are presented in the column “needOCR”. By comparing the needOCR number of pages with the number of total pages one can decide if a PDF file needs additional OCR processing.
Upvotes: 1
Reputation: 63
XPDF worked for me in a different way. But not sure it is the right way.
My PDFs with image also gave text content. So I used pdffonts.exe to verify if the fonts are embedded in the document or not.In my case all image files showed 'no' for embedded value.
> Config Error: No display font for 'Symbol'
> Config Error: No display font for 'ZapfDingbats'
> name type emb sub uni object ID
> ------------------------------------ ----------------- --- --- --- ---------
> Helvetica Type 1 no no no 7 0
Where as all searchable PDFs gave 'yes'
> Config Error: No display font for 'Symbol'
> Config Error: No display font for 'ZapfDingbats'
> name type emb sub uni object ID
> ------------------------------------ ----------------- --- --- --- ---------
> ABCDEE+Calibri TrueType yes yes no 7 0
> ABCDEE+Calibri,Bold TrueType yes yes no 9 0
Upvotes: 2
Reputation: 20267
I would write a small script to extract the text from the PDF files and see if it is "empty". If there is text the PDF already was OCRed. You could either use ghostscript or XPDF to extract the text.
EDIT: This should get you started:
foreach ($pdffile in get-childitem -filter *.pdf){
$pdftext=invoke-expression ("\path\to\xpdf\pdftotext.exe '"+$pdffile.fullname+"' -");
write-host $pdffile.fullname
write-host $pdftext.length;
write-host $pdftext;
write-host "-------------------------------";
}
Unfortunately even when you have only images in your PDF pdftotext
will extract some text, so you will have to do some more work to check whether you need to OCR the pdf.
Upvotes: 6