title: Extract specific data from .pdf and save in Excel file
body: <p>Every month I need extract some data from .pdf files to create an Excel table.</p>
  
  <p>I'm able to convert the .pdf file to text but I'm not sure how to extract and save the specific information I want. Now I have this code:</p>
  
  <pre><code>from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
  from pdfminer.converter import TextConverter
  from pdfminer.layout import LAParams
  from pdfminer.pdfpage import PDFPage
  from cStringIO import StringIO
  
  def convert_pdf_to_txt(path):
      rsrcmgr = PDFResourceManager()
      retstr = StringIO()
      codec = 'utf-8'
      laparams = LAParams()
      device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
      fp = file(path, 'rb')
      interpreter = PDFPageInterpreter(rsrcmgr, device)
      password = ""
      maxpages = 0
      caching = True
      pagenos=set()
      fstr = ''
      for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages,    password=password,caching=caching, check_extractable=True):
          interpreter.process_page(page)
  
          str = retstr.getvalue()
          fstr += str
  
      fp.close()
      device.close()
      retstr.close()
      return fstr
  
  print convert_pdf_to_txt("FA20150518.pdf")
  </code></pre>
  
  <p>And this is the result:</p>
  
  <pre><code>    &gt;&gt;&gt; 
  AVILA 72, VALLDOREIX
  08197 SANT CUGAT DEL VALLES
  (BARCELONA)
  TELF: 935441851
  NIF: B65512725
  EMAIL: buendialogistica@gmail.com
  
  JOSE LUIS MARTINEZ LOPEZ
  
  AVDA. DEL ESLA, 33-D
  24240 SANTA MARIA DEL PARAMO
  LEON
  TELF: 600871170
  
  FECHA
  17/06/15
  
  FACTURA
    20150518
  
  CLIENTE
  43000335
  
  N.I.F.
  
  71548163 B
  
  PÁG.
  
  1
  
  Nº VIAJE
  
  RUTA
  
  DESTINATARIO / REFERENCIA
  
  KG
  
  BULTOS
  
  IMPORTE
  
  2015064210-08/06/15
  
  CERDANYOLA DEL VALLES -&gt; VINAROS
  
  FERRER ALIMENTACION - VINAROZ
  
  2,000.0
  
  1
  
           150,00
  
  TOTAL IMP.
  
  %
  
  IMPORTE
  
  BASE
  
           150,00
  
           150,00
  
  %
   21,00
  
  IVA
  
  %
  
  REC.
  
  TOTAL FRA.
  
  (€)
  
            31,50
  
           181,50
  
  Eur
  
  Forma Pago:
  Banco:
  
  CONTADO
  
  Vencimientos:
  17/06/15
  181,50
  </code></pre>
  
  <p>Ok, now I have the text in the variable convert_pdf_to_txt.</p>
  
  <p>I want extract this information: Customer, Number of bill, Price, expiration date and way to pay.</p>
  
  <p>Customer name always are down "EMAIL: buendialogistica@gmail.com"</p>
  
  <p>Number of bill always are down "FACTURA"</p>
  
  <p>Price always are down two lines "Vencimientos:"</p>
  
  <p>Expiration date always are down "Vencimientos:"</p>
  
  <p>Way to pay always down "Banco:"</p>
  
  <p>I think in do something like this. If I can convert this text into a list and can do something like this:</p>
  
  <p><strong>Searching Customer:</strong></p>
  
  <pre><code> i=0
   while i &lt; lengthlist
     if listitem[i] == "EMAIL: buendialogistica@gmail.com"
        i+1
        Customer = listitem[i]
        i = lengthlist
     else:
       i+1
  </code></pre>
  
  <p><strong>Searching bill Number:</strong></p>
  
  <pre><code> i=0
   while i &lt; lengthlist
     if listitem[i] == "FACTURA"
        i+1
        Customer = listitem[i]
        i = lengthlist
     else:
       i+1
  </code></pre>
  
  <p>After I don't know how to save in Excel but I'm sure I can find examples in the forum but first I need to extract only this data.</p>