title: Adding page numbers in a text from a PDF file in Python
body: <p>The following Python program reads a PDF file and collects unique words used in that file.</p>
  
  <pre><code>import PyPDF2
  import re
  
  print('process started')
  
  pdfFile = open('pdf_file.pdf', 'rb')
  pdfFileReader = PyPDF2.PdfFileReader(pdfFile)
  pdfFilePageCount = pdfFileReader.numPages
  
  pdfPageText = ""
  for i in range(pdfFilePageCount):
      pageObj = pdfFileReader.getPage(i)
      pdfPageText += pageObj.extractText()
  
  pdfPageText = pdfPageText.lower()
  pdfPageText = re.sub(r'[^a-zA-Z]+', ' ', pdfPageText)
  listOfWords = pdfPageText.split()
  
  setPage = set(listOfWords)  
  
  textFile = open('text_file.txt', 'w')
  for item in listOfWords:
    textFile.write("%s\n" % item)
  
  textFile.close()
  pdfFile.close()
  print('process ended')
  </code></pre>
  
  <p>Is it possible to add page numbers with each word (i.e. to indicate from which page they were picked)?</p>
  
  <p>For instance, if a word "xyzabc" is found in multiple pages, I need to list them all as follows:</p>
  
  <pre><code>xyzabc (1,22,130, ...)
  </code></pre>