read_tables.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import tabula
  2. import camelot
  3. import subprocess
  4. import re
  5. #tables = tabula.read_pdf("iso_documents/ISO2768-1.PDF", pages=3)
  6. #for table in tables:
  7. # print(table)
  8. #pdftotext - layout!!!!
  9. #tabula.convert_into("iso_documents/ISO2768-1.PDF", "output_mit_tabula.csv", output_format="csv", pages='all', multiple_tables=True)
  10. #df = tabula.read_pdf("iso_documents/ISO1101.PDF", pages='all', multiple_tables=True)
  11. #print(df)
  12. def file_read(fname):
  13. content_array = []
  14. with open(fname) as f:
  15. # Content_list is the list that contains the read lines.
  16. for line in f:
  17. content_array.append(line.strip().replace(" ",""))
  18. print(content_array)
  19. #file_read('drawings/5129275_Rev01-GV12.txt')
  20. tables = camelot.read_pdf("iso_documents/ISO2768-1.PDF", pages="3")
  21. tables.export('output_mit_camelot.csv', f='csv')
  22. output = subprocess.check_output(["less","iso_documents/ISO2768-1.PDF"])
  23. re_data_prefix = re.compile("^[0-9]+[.].*$")
  24. re_data_fields = re.compile("(([^ ]+[ ]?)+)")
  25. for line in output.splitlines():
  26. if re_data_prefix.match(line):
  27. for l in re_data_fields.findall(line):
  28. print[l[0].strip()]