-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequitybankstatement_pdf_protector.py
More file actions
105 lines (78 loc) · 3.19 KB
/
equitybankstatement_pdf_protector.py
File metadata and controls
105 lines (78 loc) · 3.19 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
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
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
from PyPDF2 import PdfWriter, PdfReader # pip install PyPDF2
import os
root =Tk()
root.title("PDF Protector")
root.geometry("480x430+300+100")
root.resizable(False, False)
def browse():
global filename
filename=filedialog.askopenfilename(initialdir=os.getcwd(),
title="Select PDF file",
filetype=(('PDF file','*.pdf'),('All files','*.*')))
entry1.insert(END, filename)
def Protect():
mainfile=source.get()
protectedfile=target.get()
code=password.get()
# print(mainfile)
# print(protectedfile)
# print(code)
if mainfile=="" and protectedfile=="" and password.get()=="":
messagebox.showerror("error", "Browse pdf file, new name to save and Enter password!!")
elif mainfile=="":
messagebox.showerror("Invalid", "Please type SOURCE pdf filename!")
elif protectedfile=="":
messagebox.showerror("Invalid", "Please type TARGET pdf filename!")
elif code=="":
messagebox.showerror("Invalid", "Please type Your PASSWORD to protect pdf file!")
else:
try:
out=PdfWriter()
file=PdfReader(filename)
number_of_pages = len(file.pages)
for idx in range(number_of_pages):
# page=file.getPage(idx)
page = file.pages[0]
out.add_page(page)
# password
out.encrypt(code)
with open(protectedfile, "wb") as f:
out.write(f)
source.set("")
target.set("")
password.set("")
messagebox.showinfo("Saved", "Protected Pdf saved successfully!")
except:
messagebox.showerror("Invalid", "Invalid Entry!")
#icon
image_icon = PhotoImage(file="Images/icon.png")
root.iconphoto(False, image_icon)
#main
top_image=PhotoImage(file="Images/top.png")
label=Label(root, image=top_image).pack()
frame=Frame(root, width=460, height=310,bd=5, relief=GROOVE)
frame.place(x=10,y=110)
#####################333
source=StringVar()
Label(frame, text="Source PDF file:", font="arial 10 bold", fg="#4c4542").place(x=10,y=42)
entry1=Entry(frame, width=20, textvariable=source, font="arial 15", bd=1)
entry1.place(x=130,y=40)
button_icon =PhotoImage(file="Images/button image.png")
Button(frame, image=button_icon, width=35,height=24, bg="#d3cdcd", command=browse).place(x=370, y=38)
#####################333
target=StringVar()
Label(frame, text="Target PDF file:", font="arial 10 bold", fg="#4c4542").place(x=10,y=84)
entry2=Entry(frame, width=20, textvariable=target, font="arial 15", bd=1)
entry2.place(x=130,y=84)
#####################333
password=StringVar()
Label(frame, text="Set User Password", font="arial 10 bold", fg="#4c4542").place(x=5,y=126)
entry3=Entry(frame, width=20, textvariable=password, font="arial 15", bd=1)
entry3.place(x=130,y=124)
button_icon2 =PhotoImage(file="Images/button.png")
Protect=Button(root, text="Protect PDF file", compound=LEFT, image=button_icon2, width=200,height=40, bg="#bfb9b9", font="arial 14 bold", command=Protect)
Protect.place(x=150, y=320)
root.mainloop()