forked from dumbbanana/automate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit_it.py
33 lines (26 loc) · 969 Bytes
/
split_it.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from PyPDF2 import PdfFileWriter as PfW, PdfFileReader as PfR
import csv
def split_the_pdf(pdf_file_name, csv_file_name):
# CSV file to get the participant name
reader_handle = open(csv_file_name, 'r')
reader = csv.reader(reader_handle)
header = next(reader)
# PDF file handle stuff
pdf_infile = open(pdf_file_name, 'rb')
pdf_reader = PfR(pdf_infile)
# Page numbers for getPage() begins wth 0
page_number = 0
for row in reader:
output_filename = row[0] + ".pdf"
# The actual creation of the new PDFs
pdf_writer = PfW()
pdf_writer.addPage(pdf_reader.getPage(page_number))
outfile = open(output_filename, 'wb')
pdf_writer.write(outfile)
outfile.close()
page_number += 1
print("Page Number :", page_number)
# Closing the connection to the input file
pdf_infile.close()
if __name__ == '__main__':
split_the_pdf('allcerts.pdf', 'details.csv')