-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDF-Split.py
49 lines (45 loc) · 1.55 KB
/
PDF-Split.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
38
39
40
41
42
43
44
45
46
47
48
49
from PyPDF2 import PdfFileWriter, PdfFileReader
def one_split(file, page, name):
page = page - 1
pdfFileObj = open(file + ".pdf", 'rb')
pdfReader = PdfFileReader(pdfFileObj)
output = PdfFileWriter()
output.addPage(pdfReader.getPage(page))
with open(name + ".pdf", "wb") as outputStream:
output.write(outputStream)
def multiple_split(file, pages, name):
pages[0], pages[1] = int(pages[0]) - 1, int(pages[1])
pdfFileObj = open(file + ".pdf", 'rb')
pdfReader = PdfFileReader(pdfFileObj)
output = PdfFileWriter()
for i in range(pages[0], pages[1]):
output.addPage(pdfReader.getPage(i))
with open(name + ".pdf", "wb") as outputStream:
output.write(outputStream)
while True:
file = input("Dime el nombre del PDF que queres separar: ")
page = input("Dime el numero de la página (INT) que queres separar o el rango de paginas (INT-INT): ")
try:
page = int(page)
name = input("Dime el nombre del nuevo PDF quieres tener: ")
one_split(file, page, name)
print("Éxito...")
print()
action = input("Queres seguir? (Y/N)").lower()
if action == "n":
break
except:
try:
page = page.split("-")
except:
pass
name = input("Dime el nombre del nuevo PDF quieres tener: ")
multiple_split(file, page, name)
print("Éxito...")
print()
action = input("Queres seguir? (Y/N)").lower()
if action == "n":
break
else:
pass
pass