开发者

How to identify PDF files that need OCR?

开发者 https://www.devze.com 2023-04-12 07:03 出处:网络
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?

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 a开发者_Python百科n OCR processor.


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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消