-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfgen.py
64 lines (53 loc) · 1.63 KB
/
pdfgen.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Import all libraries
import img2pdf
import os
from PIL import Image
from tkinter import *
import dirSelector
def removealpha(inpath):
print('Converting Image into non alpha channel image')
for file in os.listdir(inpath):
img = Image.open(inpath+file)
size = img.size
imgnew = Image.new('RGB',size,255)
imgnew.paste(img,(0,0))
imgnew.save('out/'+file)
print('Image Conversion done.')
def pdfGen(inpath,outpath):
l = os.listdir(inpath)
lst = []
print('PDF Creating...')
for i in l:
lst.append(open((inpath+i),'rb'))
with open('out.pdf','wb') as f:
f.write(img2pdf.convert(lst))
print('PDF Generation done.')
def browse_button():
from tkinter import filedialog
# Allow user to select a directory and store it in global var
# called folder_path
global folder_path
filename = filedialog.askdirectory()
folder_path.set(filename)
print(filename)
def guiGen():
master = Tk()
master.wm_minsize(width=200, height=200)
Label(master, text='Input Directory').grid(row=0)
Label(master, text='Output Directory').grid(row=1)
folder_path = StringVar()
e1 = Button(master, text='Select', width=10,command=browse_button)
e2 = Button(master, text='Select', width=10,command=browse_button)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
button = Button(master, text='Stop', width=25, command=master.destroy)
button.grid(row=2, column=1)
mainloop()
def main():
guiGen()
# inpath = 'ada/'
# outpath = 'result/'
# removealpha(inpath)
# pdfGen('out/',outpath)
if __name__ == "__main__":
main()