It’s the time of the year I have to generate expense reports and I need three details for the invoices. First the invoice number, second the invoice date and the third gross amount paid.
Now the Uber invoice is pdf as shown in figure below:
As opening PDF files and getting data from it manually was kind of painful, so I wrote a python script for my help. Here it is:
import PyPDF2 import os dirPath = 'C:/path_to_directory_containing_invoices/' os.chdir(dirPath) fileList = os.listdir() for fileName in fileList: f = open(dirPath+fileName, 'rb') reader = PyPDF2.PdfFileReader(f) contents = reader.getPage(0).extractText().split('\n') invoice_number = "" invoice_date = "" gross_amount = "" for i in range(len(contents)): if contents[i].find("Invoice Number") != -1: invoice_number = contents[i].split(': ') if contents[i].find("Invoice Date") != -1: invoice_date = contents[i].split(': ') if contents[i].find("Gross Amount") != -1: gross_amount = contents[i+1].split(' ') print(invoice_number + ", " + invoice_date + ", " + gross_amount) f.close()
It uses PyPDF library. This link tells you how to install it and use it.