I am using PyPDF2 to extract the data from PDF file and then converting into Text format?
PDF format for the file is like this:
Name : John
Address: 123street , USA
Phone No: 123456
Gender: Male
Name : Jim
Address: 456street , USA
Phone No: 456899
Gender: Male
In Python I am using this code:
import PyPDF2
pdf_file = open('C:\\Users\\Desktop\\Sampletest.pdf', 'rb')
read_pdf = PyPDF2.PdfFileReader(pdf_file)
number_of_pages = read_pdf.getNumPages()
page = read_pdf.getPage(0)
page_content = page.extractText()
page_content
This is the outcome which I get from page_content:
'Name : John \n \nAddress: 123street , USA \n \nPhone No: 123456\n \nGender: Male \n \n \nName : Jim \n \nAddress: 456street , USA \n \nPhone No: 456899\n \nGender: Male \n \n \n'
How do I format it in a JSON or XML format so that I could use extracted data in SQL server database.
I tried using this approach as well
import json
data = json.dumps(page_content)
formatj = json.loads(data)
print (formatj)
Output:
Name : John
Address: 123street , USA
Phone No: 123456
Gender: Male
Name : Jim
Address: 456street , USA
Phone No: 456899
Gender: Male
This is the same output which I have in my word file, but I don't think that this is in JSON format.
print(page_content)
instead? Having one variable on a line by itself doesn't produce any output in a script