title: How to extract table as text from the PDF using Python?
body: <p>I have a PDF which contains Tables, text and some images. I want to extract the table wherever tables are there in the PDF.</p>
  
  <p>Right now am doing manually to find the Table from the page. From there I am capturing that page and saving into another PDF.</p>
  
  <pre><code>import PyPDF2
  
  PDFfilename = "Sammamish.pdf" #filename of your PDF/directory where your PDF is stored
  
  pfr = PyPDF2.PdfFileReader(open(PDFfilename, "rb")) #PdfFileReader object
  
  pg4 = pfr.getPage(126) #extract pg 127
  
  writer = PyPDF2.PdfFileWriter() #create PdfFileWriter object
  #add pages
  writer.addPage(pg4)
  
  NewPDFfilename = "allTables.pdf" #filename of your PDF/directory where you want your new PDF to be
  with open(NewPDFfilename, "wb") as outputStream:
      writer.write(outputStream) #write pages to new PDF
  </code></pre>
  
  <p>My goal is to extract the table from the whole PDF document.</p>
  
  <p><strong><a href="https://i.stack.imgur.com/0kWSg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0kWSg.png" alt="Please have a look at the sample image of a page in PDF"></a></strong></p>