-
Notifications
You must be signed in to change notification settings - Fork 2
/
pdf_spilter.py
37 lines (33 loc) · 1.25 KB
/
pdf_spilter.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
34
35
36
37
# -------------------------------------------------------------------------------
# Name: pdf spiller
# Purpose: split pdf in to single pages
# Author: acer
# Created: 13-04-2018
# Copyright: (c) acer 2018
# Licence: <your licence>
# -------------------------------------------------------------------------------
import os
import sys # module for terminating
import glob #
import tkinter as tk
from tkinter import filedialog
from PyPDF2 import PdfFileReader, PdfFileWriter
def pdf_splitter(path, dest):
fname = os.path.splitext(os.path.basename(path))[0]
pdf = PdfFileReader(path)
for page in range(pdf.getNumPages()):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdf.getPage(page))
output_filename = os.path.join(
dest, '{}_page_{}.pdf'.format(fname, page+1))
# print(output_filename)
with open(output_filename, 'wb') as out:
pdf_writer.write(out)
print('Created: {}'.format(output_filename))
if __name__ == '__main__':
#path = "Computer_Science.pdf"
root = tk.Tk()
root.withdraw()
path = filedialog.askopenfilename() # source file name
dest = filedialog.askdirectory() # destination folder
pdf_splitter(path, dest)