Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. file_path = 'InputFiles'
  2. #file_path = 'PDFInput'
  3. for file in os.listdir(file_path):
  4. if file.endswith('.pdf') or file.endswith('.PDF'):
  5. #print(file)
  6. pdf = pdfquery.PDFQuery(file_path+'/'+file)
  7. num_paginas = pdf.doc.catalog['Pages'].resolve()['Count']
  8. #print('Num: ', num_paginas)
  9.  
  10. for pagina in range(0, num_paginas, 2):
  11. #print('Pagina: ', pagina)
  12. pdf.load(pagina)
  13. pdf.tree
  14.  
  15. line = 0
  16. for etiqueta in pdf.tree.iter():
  17. line = line + 1
  18. #print(str(tag)+' '+str(tag.text))
  19. #print(str(line)+' '+str(etiqueta.text))
  20.  
  21. if line == 59:
  22. num_serie = etiqueta.text.strip()
  23. if line == 61:
  24. fecha = etiqueta.text.strip()
  25. if line == 66:
  26. num_factura = etiqueta.text.strip()
  27. if line == 90:
  28. descripcion = etiqueta.text.strip()
  29. if line == 91:
  30. centro = etiqueta.text[8:12].strip()
  31. if line == 103:
  32. precio_unitario = etiqueta.text.strip()
  33.  
  34. print(str(file)
  35. +' '+str(num_paginas)
  36. +' '+str(pagina+1)
  37. +' '+str(num_serie)
  38. +' '+str(fecha)
  39. +' '+str(num_factura)
  40. +' '+str(descripcion)
  41. +' '+str(centro)
  42. +' '+str(precio_unitario))
  43.  
  44.  
  45. print('FIN')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement