title: How to read simple text from a PDF file with Python?
body: <p>Need to parse a PDF file in order to extract just the first initial lines of text, and have looked for different Python packages to do the job, but without any luck.</p>
  
  <p>Having tried:</p>
  
  <ul>
  <li><p><a href="https://github.com/euske/pdfminer" rel="noreferrer">PDFminer</a>, <a href="https://github.com/pdfminer/pdfminer.six" rel="noreferrer">PDFminer.six</a> and <a href="https://pypi.org/project/pdfminer3k/" rel="noreferrer">PDFminer3k</a>, which appears to be overly complex for the simple job, and I was unable to find a simple working example</p></li>
  <li><p><a href="https://pypi.org/project/slate/" rel="noreferrer">slate</a>, got <a href="https://github.com/timClicks/slate/issues/38" rel="noreferrer">error</a> in installation, though worked with fix from thread, but got error when trying; maybe using wrong PDFminer, but can't figure which to use</p></li>
  <li><p><a href="https://pypi.org/project/PyPDF2/" rel="noreferrer">PyPDF2</a> and <a href="https://github.com/mstamy2/PyPDF3/blob/master/PyPDF3/pdf.py" rel="noreferrer">PyPDF3</a> but these gave garbage as described <a href="https://stackoverflow.com/questions/34837707/how-to-extract-text-from-a-pdf-file">here</a></p></li>
  <li><p><a href="https://github.com/chrismattmann/tika-python" rel="noreferrer">tika</a>, that gave different terminal error messages and was very slow</p></li>
  <li><p><a href="https://pypi.org/project/pdftotext/" rel="noreferrer">pdftotext</a> failed to install</p></li>
  <li><p><a href="https://simply-python.com/tag/pdf2text/" rel="noreferrer">pdf2text</a> failed at "import pdf2text", and when changed to "pdftotext" failed to import with "ImportError: cannot import name 'Extractor'" even through <code>pip list</code> shows that "Extractor" is installed</p></li>
  </ul>
  
  <p>Usually I find that installed Python packages work amazingly well, but parsing PDF to text appears to be a jungle, which the myriad of tools also indicates.</p>
  
  <p>Any suggestion of how to do simple parsing of a PDF file to text in Python?</p>
  
  <p><strong>PyPDF2 example added</strong></p>
  
  <p>An example of PyPDF2 is:</p>
  
  <pre><code>import PyPDF2
  pdfFileObj = open('file.pdf', 'rb')
  pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
  pageObj_0 = pdfReader.getPage(0)
  print(pageObj_0.extractText())
  </code></pre>
  
  <p>Which returns garbage as:</p>
  
  <blockquote>
    <p>$%$%&amp;%&amp;$'(' ˜!)"*+#</p>
  </blockquote>