Commit 87056023 authored by Olivier's avatar Olivier
Browse files

M10: simpler PDF form reading methods

parent 9e59e417
......@@ -16,7 +16,7 @@ Conditions:
"""-------------------------Hard coded input--------------------------------"""
# Output file name
csv_file_name = 'grades.csv' # Output csv file name (to store grades)
csv_file_name = 'script_output/grades.csv' # Output csv file name (to store grades)
"""-------------------------------------------------------------------------"""
# Import modules
......@@ -25,7 +25,7 @@ import PyPDF2 # For working with PDFs
import csv # For reading cvs files
# List of all the files in the directory
list_of_files = os.listdir()
list_of_files = os.listdir(path='.')
# Filter only ".pdf" files
list_of_pdf_files = []
......@@ -42,7 +42,8 @@ object = open(calibration_pdf, 'rb') # rb means read binary
reader = PyPDF2.PdfFileReader(object)
# Get values from text boxes in the PDF
text_boxes_data = reader.getFormTextFields()
#text_boxes_data = reader.getFormTextFields() # Deprecated, now getFields() works
text_boxes_data = reader.getFields()
# Create headers for the csv file
headers = []
......@@ -61,12 +62,13 @@ for pdf_file in list_of_pdf_files:
reader = PyPDF2.PdfFileReader(object)
# Get values from text boxes in the PDF
text_boxes_data = reader.getFormTextFields()
#text_boxes_data = reader.getFormTextFields() # Deprecated, now getFields() works
text_boxes_data = reader.getFields()
# Get grades for the student
student_grades = []
for i in range(len(text_boxes_names)):
grade = text_boxes_data.get(text_boxes_names[i], "")
grade = text_boxes_data.get(text_boxes_names[i], "").get("/V")
student_grades.append(str(grade))
# Add pdf file-name and the student's grades to the "line_data" array
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment