-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
185 lines (144 loc) Β· 7.29 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import WPDF
run = True
def cnv_pdf():
print("""
Convertion file options:
1 > Text to pdf
2 > Document to pdf
3 > images to pdf
Note: If the destination folder is not given the source Folder is taken as destination folder
""")
cnv_opt = ''
while not (cnv_opt == "1" or cnv_opt == "2" or cnv_opt == "3" or cnv_opt == "q"):
cnv_opt = input("Choose option: ").lower()
if cnv_opt == '1':
src = input("Enter the source folder with file name(Ex: F:/blah/example.txt): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
num = input("Enter chapter number: ")
title = input("Enter the chapter title: ")
txt2pdf = WPDF.TxtPDF()
txt2pdf.print_chapter(name=src, num=num, title=title)
txt2pdf.output(dst, 'F')
print(f'New pdf has been created from {src} to {dst}')
elif cnv_opt == '2':
src = input("Enter the source folder with file name(Ex: F:/blah/example.docx): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
print(f'New pdf has been created from {src} to {dst}')
convert = WPDF.PdfCon(src, dst)
convert.doc_pdf()
elif cnv_opt == '3':
src = input("Enter the source folder (Ex: F:/blah/): ")
dst = input("Enter the destination folder (Ex: D:/blah/): ")
print(f'New pdf has been created from {src} to {dst}')
img_pdf = WPDF.PdfCon(src, dst)
img_pdf.img_pdf()
def pdf_op():
print("""
Convertion file options:
1 > PDF INFO 2 > Extract text from a page
3 > Rotate a particular page
4 > Rotate Whole pdf 5 > Merge pdf's
6 > Reverse the order of pdf
7 > split the pdf upto the page number given
8 > split the pdf from the page number given
9 > Water-mark the pdf
10 > password protect the pdf
Note: If the destination folder is not given the source Folder is taken as destination folder
""")
pdf_opt = ''
while not (pdf_opt == "1" or pdf_opt == "2" or pdf_opt == "3" or pdf_opt == "4" or pdf_opt == "5"
or pdf_opt == "6" or pdf_opt == "7" or pdf_opt == "8" or pdf_opt == "9" or pdf_opt == "10"):
pdf_opt = input("Choose option: ").lower()
if pdf_opt == "1":
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.txt): ")
info = WPDF.PdfFunc(src, dst)
info.pdf_info()
elif pdf_opt == "2":
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.txt): ")
num = input("Enter the page number you want to extract text from: ")
extract = WPDF.PdfFunc(src, dst)
extract.ext_txt(int(num))
elif pdf_opt == "3":
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
num = int(input("Enter the page number you want to rotate: "))
rot = int(input("Enter the angle you want to rotate (ex: 90 or -90): "))
protate = WPDF.PdfFunc(src, dst)
protate.pdf_rotate_page(rot, num)
elif pdf_opt == "4":
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
rot = int(input("Enter the angle you want to rotate (ex: 90 or -90): "))
rotate = WPDF.PdfFunc(src, dst)
rotate.rotate_pdf(rot)
elif pdf_opt == "5":
src = input("Enter the source folder with file name(Ex: F:/blah/1.pdf,F:/blah/2.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
merge = WPDF.PdfFunc(src, dst)
merge.merge_pdf()
elif pdf_opt == "6":
print(" This function reverses the order of pdf")
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
reverse = WPDF.PdfFunc(src, dst)
reverse.reverse_pdf()
elif pdf_opt == "7":
print(" This function splits upto the page number given and returns a new pdf")
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
split = int(input("Enter the page number upto which the pdf should split: "))
fh_split = WPDF.PdfFunc(src, dst)
fh_split.split_fh_pdf(split)
elif pdf_opt == "8":
print(" This function splits from the page number given and returns a new pdf")
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
split = int(input("Enter the page number you want to start the pdf to split: "))
sh_split = WPDF.PdfFunc(src, dst)
sh_split.split_sh_pdf(split)
elif pdf_opt == "9":
print(" This function add water mark to entire pdf. The watermark should to in the pdf format")
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
marker = input("Enter the location of watermark pdf file: ")
w_m = WPDF.PdfFunc(src, dst)
w_m.watermark(marker)
elif pdf_opt == "10":
print(" This function password protect the pdf")
src = input("Enter the source folder with file name(Ex: F:/blah/example.pdf): ")
dst = input("Enter the destination folder (Ex: F:/blah/something.pdf): ")
password = input("Enter your password: ")
encrypt = WPDF.PdfFunc(src, dst)
encrypt.encrypt(password)
def main():
try:
print("""
Choose operation :
1 > convert to pdf
2 > PDF Functions (ex: rotate a pdf, password protect pdf, etc.,)
q > Quit
""")
main_opt = ''
while not (main_opt == '1' or main_opt == '2' or main_opt == 'q'):
main_opt = input("Choose option: ").lower()
if main_opt == '1':
cnv_pdf()
elif main_opt == '2':
pdf_op()
elif main_opt == 'q':
quit()
else:
pass
except Exception as e:
print(e)
while run:
main()
repeat = input("Do you want to continue? Enter 'y' or 'n': ")
if repeat[0].lower() == 'y':
run = True
continue
else:
print("Thank you!")
break