Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine programmatically if a PDF is searchable?

I have a CSV with a list of URLs with PDFs:

  • Some of these PDFs are searchable.
  • Some of these PDFS aren't searchable.

I want to determine which PDFs are searchable from my list of PDFs. Is there an easy way to do this?

like image 717
user1507889 Avatar asked Aug 05 '12 21:08

user1507889


1 Answers

On the commandline, I'd use pdffonts to determine which fonts the file uses. This runs rather fast as well...

Example 1: PDF containing text

pdffonts bash-manpage.pdf 
  
  name                            type          encoding        emb sub uni object ID
  ------------------------------- ------------- --------------- --- --- --- ---------
  Times-Roman                     Type 1        Custom          no  no  no       8  0
  Times-Bold                      Type 1        Standard        no  no  no       9  0
  Helvetica                       Type 1        Custom          no  no  no      11  0
  Helvetica-Bold                  Type 1        Standard        no  no  no      30  0

Example 2: PDF containing only images

pdffonts scanned-book.pdf
  
  pdffonts handmade.pdf 
  name                            type           encoding       emb sub uni object ID
  ------------------------------- -------------- -------------- --- --- --- ---------

  1. Example 1 shows a table with font names. This means there IS text to search.

  2. Example 2 shows an empty table. No fonts, no text to be searched (unless you run OCR on the file to first embed any found text... but then you've created a different file!), don't look back at these...

Note: to be successful in actually extracting the embedded text and hence being able to search it is an entirely different problem. There are many cases where you'll find it to be extremely difficult -- especially if you see in the fonts' table font types like CID Type with 'custom' encoding. You may first want to search stackoverflow for other questions that were asked about text extraction from PDF...

like image 75
Kurt Pfeifle Avatar answered Oct 17 '22 23:10

Kurt Pfeifle