title: Excluding the Header and Footer Contents of a page of a PDF file while extracting text?
body: <p>Is it possible to exclude the <code>contents of footers and headers of a page</code> from a pdf file during extracting the text from it. As these contents are least important and almost redundant.</p>
  
  <p>Note: For extracting the text from the .pdf file, I am using the PyPDF2 package on python version = 3.7. </p>
  
  <p>How to exclude the contents of the footers and headers in PyPDF2. Any help is appreciated.</p>
  
  <p>The code snippet is as follows:</p>
  
  <pre><code>import PyPDF2
  
  def Read(startPage, endPage):
      global text
      text = []
      cleanText = " "
      pdfFileObj = open('C:\\Users\\Rocky\\Desktop\\req\\req\\0000 - gamma j.pdf', 'rb')
      pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
      num_pages = pdfReader.numPages
      print(num_pages)
      while (startPage &lt;= endPage):
          pageObj = pdfReader.getPage(startPage)
          text += pageObj.extractText()
          startPage += 1
      pdfFileObj.close()
      for myWord in text:
          if myWord != '\n':
             cleanText += myWord
      text = cleanText.strip().split()
      print(text)
  
  Read(1, 1)
  </code></pre>