SHARE
TWEET

Untitled

a guest Sep 16th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # modules for
  2. import PyPDF2
  3. import csv
  4. import os
  5. path=os.getcwd()
  6. files = []
  7. # r=root, d=directories, f = files
  8. for r, d, f in os.walk(path):
  9.     for file in f:
  10.         if '.pdf' in file:
  11.             files.append(os.path.join(r, file))
  12.  
  13. for f in files:
  14.     print(f)
  15.     # pdf file object
  16.     # you can find find the pdf file with complete code in below
  17.     pdfFileObj = open(f, 'rb')
  18.     # pdf reader object
  19.     pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
  20.     # number of pages in pdf
  21.     # a page object
  22.     pageObj = pdfReader.getPage(0)
  23.  
  24.     # extracting text from page.
  25.     # this will print the text you can also save that into String
  26.     BSCnum = pageObj.extractText().find("N°")
  27.     Exporter = pageObj.extractText().find("Shipper:")
  28.     BL=pageObj.extractText().find("Bill Of Lading :")
  29.     Consignee=pageObj.extractText().find("Destinataire")
  30.     Contdet=pageObj.extractText().find("nb 20':")
  31.     Numero=pageObj.extractText().find("NUMERO")
  32.     COL=pageObj.extractText().find("Pays d'embarquement")
  33.     FD=pageObj.extractText().find("Final Destination")
  34.     Vessel=pageObj.extractText().find("Vessel:")
  35.     valdate=pageObj.extractText().find("Validation Date")
  36.  
  37.  
  38.     cikti = pageObj.extractText()[BSCnum:BSCnum+12],pageObj.extractText()[valdate+20:valdate+28],pageObj.extractText()[Exporter+20:BL],pageObj.extractText()[Consignee+13:Vessel],pageObj.extractText()[BL+31:Consignee-12],pageObj.extractText()[Contdet:Numero],pageObj.extractText()[COL+20:FD]
  39.     with open('besc.csv', 'a+', newline='') as csvfile:
  40.             spamwriter = csv.writer(
  41.                 csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
  42.             spamwriter.writerow(cikti)
  43.     with open('progress.csv', 'a+', newline='') as csvfile:
  44.             spamwriter = csv.writer(
  45.                 csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
  46.             spamwriter.writerow(f)
  47.  
  48.     os.remove(f)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top