user1507889
user1507889

Reputation: 473

How do I determine programmatically if a PDF is searchable?

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

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

Upvotes: 7

Views: 6756

Answers (1)

Kurt Pfeifle
Kurt Pfeifle

Reputation: 90315

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...

Upvotes: 10

Related Questions