Convert Data From Pdfform To Csv
I am trying to convert the data entered in multiple fill-able pdf-forms to one csv file. This code consists of a few steps: Open new .csv file (header row) Open multiple pdf-forms
Solution 1:
Try changing the last part of your code as shown:
.
.
.
#enter folder path to open multiple files
path = 'C:\Users\Wonen\Downloads\Test'for filename in glob.glob(os.path.join(path, '*.pdf')):
fp = open(filename, 'rb')
#read pdf's
parser = PDFParser(fp)
doc = PDFDocument(parser)
#doc.initialize() # <<if password is required
fields = resolve1(doc.catalog['AcroForm'])['Fields']
row = []
for i in fields:
field = resolve1(i)
name, value = field.get('T'), field.get('V')
row.append(value)
writer.writerow(row)
out_file.close()
It's not clear this will work, but it may provide you with the information you need to solve your problem.
One confusing thing is that for the first header row of the csv:
writer.writerow(('Name coordinator', 'Date', 'Address','District','City', 'Complaintnr'))
which defines how many field values will be contained in each row written. This means that fields
should be a list consisting of data for those 6 items in that order.
You need to figure out how to translate what's in each group of fields
into a row
list of 6 data items. That is what the code in my answer does — I think, but can't test.
Post a Comment for "Convert Data From Pdfform To Csv"