Convert PDF to csv using ( data in single cell)

Viewed 125

I have one pdf file which contains the data for a different person in a single cell, I wanted to process it and convert it into CSV file using python. Any help would be appreciated. Adding the screenshot for reference.

Also it would be great if it will be converted into English.

enter image description here

1 Answers

This is a good start...

https://pypi.org/project/tabula-py/

import tabula

# Read pdf into list of DataFrame
df = tabula.read_pdf("test.pdf", pages='all')

# convert PDF into CSV file
tabula.convert_into("test.pdf", "output.csv", output_format="csv", pages='all')

Then to translate:

pip install translate

from translate import Translator
translator= Translator(from_lang="arabic",to_lang="english")
for line in df:
    #translate the line instance and update the df
    translation = translator.translate(line)

To handle complicated PDF's here are some options to play with:

from tabula import read_pdf
try:
    x = read_pdf(filename, pages=pages, multiple_tables=False, error_bad_lines=False, spreadsheet=False, silent=True)
except:
    x = read_pdf(filename, encoding='latin1', pages=true, multiple_tables=False, error_bad_lines=False, spreadsheet=False, silent=True)
Related