How do I determine programmatically if a PDF is searchable?

自闭症网瘾萝莉.ら 提交于 2020-12-01 07:30:46

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/11820241/how-do-i-determine-programmatically-if-a-pdf-is-searchable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!