title: How to ignore errors from PDFMiner in order to avoid Python script from breaking
body: <p>I'm fairly new to file handling especially PDFs. I currently have PDFminer.six installed and have tested out several functions that extracts text from PDF files. I also have another function that takes in a list of PDF files and then calls the first PDF extraction function to extract all the text from each file.</p>
  
  <p>The problem is that, I have a lot of PDF files and the script seems to break every time it encounters a new error. Its difficult to have go and search for which PDF file caused the error regardless of whether it was an unrecognized character, or different encoding, or encryption etc.. </p>
  
  <p>How can I make it so the script just continues to run regardless of the type of error? Could I set the PDF extraction function to ignore any type of error? Or perhaps, am I missing something in my code that would assist me with addressing this issue?</p>
  
  <pre class="lang-py prettyprint-override"><code>p = Path("C:/Users/Hugo Caldeira/Desktop")
  inp = r"((?&lt;=|^)[0-9]{3}-[0-9]{2}-[0-9]{4}(?=|$))"
  
  file_dict = {
      "name" : [],
      "created" : [],
      "modified" : [],
      'path' : [],
      'content' : [],
      'keyword' : []
  }
  
  files = list(p.rglob('*pdf'))
  
  def pdfparser(file):
      fp = open(file, 'rb')
      rsrcmgr = PDFResourceManager()
      retstr = io.StringIO()
      codec = 'utf-8'
      laparams = LAParams()
      device = TextConverter(rsrcmgr, retstr, codec=codec,  laparams=laparams)
      #Create a PDF interpreter object.
      interpreter = PDFPageInterpreter(rsrcmgr, device)
      #Process each page contained in the document.
      for page in PDFPage.get_pages(fp):
          interpreter.process_page(page)
          data =  retstr.getvalue()
  
      return(data)
  
  
  def pdfs(files):
      for name in files:
              #print(name)
              IP_list = (pdfparser(name))
              #print(IP_list)
              keyword = re.findall(inp,IP_list)
              #print(ip_test)
              file_dict['keyword'].append(keyword)
              file_dict['name'].append(name.name[0:])
              file_dict['created'].append(time.ctime(name.stat().st_ctime))
              file_dict['modified'].append(time.ctime(name.stat().st_mtime))
              file_dict['path'].append(name)
              file_dict["content"].append(IP_list)
              #print(file_dict)
      return(file_dict)
  
  pdfs(files)
  
  def to_xlsx():
      df = pd.DataFrame.from_dict(file_dict)
      df.head()
      df.to_excel("pdftest.xlsx")
  
  if __name__ == "__main__":
      to_xlsx()
  </code></pre>
  
  <p>The current error I am getting is:</p>
  
  <pre><code>Traceback (most recent call last):
    File "c:/Users/Hugo Caldeira/Desktop/Scripts/pdf.py", line 67, in &lt;module&gt;
      print(pdfparser(p))
    File "c:/Users/Hugo Caldeira/Desktop/Scripts/pdf.py", line 32, in pdfparser
      fp = open(file, 'rb')
  FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Hugo Caldeira\\Desktop\\test_folder\\Desktop'
  
  (base) C:\Users\Hugo Caldeira\Desktop\Scripts&gt;"C:/Users/Hugo Caldeira/Anaconda3/python.exe" "c:/Users/Hugo Caldeira/Desktop/Scripts/pdf.py"
  Traceback (most recent call last):
    File "c:/Users/Hugo Caldeira/Desktop/Scripts/pdf.py", line 64, in &lt;module&gt;
      pdfs(files)
    File "c:/Users/Hugo Caldeira/Desktop/Scripts/pdf.py", line 52, in pdfs
      IP_list = (pdfparser(name))
    File "c:/Users/Hugo Caldeira/Desktop/Scripts/pdf.py", line 42, in pdfparser
      for page in PDFPage.get_pages(fp):
    File "C:\Users\Hugo Caldeira\Anaconda3\lib\site-packages\pdfminer\pdfpage.py", line 129, in get_pages
      doc = PDFDocument(parser, password=password, caching=caching)
    File "C:\Users\Hugo Caldeira\Anaconda3\lib\site-packages\pdfminer\pdfdocument.py", line 577, in __init__
      self._initialize_password(password)
    File "C:\Users\Hugo Caldeira\Anaconda3\lib\site-packages\pdfminer\pdfdocument.py", line 603, in _initialize_password
      handler = factory(docid, param, password)
    File "C:\Users\Hugo Caldeira\Anaconda3\lib\site-packages\pdfminer\pdfdocument.py", line 303, in __init__
      self.init()
    File "C:\Users\Hugo Caldeira\Anaconda3\lib\site-packages\pdfminer\pdfdocument.py", line 310, in init
      self.init_key()
    File "C:\Users\Hugo Caldeira\Anaconda3\lib\site-packages\pdfminer\pdfdocument.py", line 325, in init_key
      raise PDFPasswordIncorrect
  pdfminer.pdfdocument.PDFPasswordIncorrect
  </code></pre>
  
  <p>The other errors I encountered before were:</p>
  
  <pre><code>PDFSyntaxError: No /Root object! - Is this really a PDF?
  </code></pre>