-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoubleprint.py
More file actions
54 lines (50 loc) · 1.72 KB
/
doubleprint.py
File metadata and controls
54 lines (50 loc) · 1.72 KB
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
50
51
52
53
54
import PyPDF2 as pdf
from pathlib import Path
f = 1
flag = input("Inkjet/Laser? type 0/1")
files = []
lastpage = pdf.PdfReader("./lastpage.pdf")
pdfodd = pdf.PdfWriter()
pdfeven = pdf.PdfWriter()
outputpath = Path(input("Output path:"))
if not outputpath.exists():
Path.mkdir(outputpath)
while (True):
while True:
din = Path(input("The PDF to process").lstrip('"').rstrip('"'))
if din.exists():
if din.is_dir():
print("will convert all pdfs")
files = list(din.glob("*.pdf"))
break
else:
if str(din).split('.')[1] == "pdf":
files.append(din)
break
print("Path not exist")
for f in files:
pdfin = pdf.PdfReader(str(f))
total = len(pdfin.pages)
for i in range(0, total, 2):
page = pdfin.pages[i]
pdfeven.add_page(page)
if (flag == '1'):
if total % 2 != 0:
tail = total-2
pdfodd.add_page(lastpage.pages[0])
else:
tail = total-1
for i in range(tail, 0, -2):
page = pdfin.pages[i]
pdfodd.add_page(page)
else:
for i in range(1, total, 2):
page = pdfin.pages[i]
pdfodd.add_page(page)
if (total+1) % 2 == 0:
pdfodd.add_page(lastpage.pages[0])
pdfodd.write(outputpath/('even'+str(f.parts[-1])))
pdfeven.write(outputpath/('odd'+str(f.parts[-1])))
outstr = "Even:%d,Odd:%d,Total:%d,File:%s" % (
len(pdfeven.pages), len(pdfodd.pages), total+1, f)
print(outstr)