-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (54 loc) · 2.41 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
import tkinter as tk
import ttkbootstrap as ttk
import tkinter.messagebox
import pikepdf
from tkinter import PhotoImage, filedialog
def protect():
pdf_location = location.get()
pdf_password = password.get()
pdf_name = new_pdf_name.get()+".pdf"
old_pdf = pikepdf.Pdf.open(pdf_location)
no_extr = pikepdf.Permissions(extract=False)
try:
old_pdf.save(pdf_name, encryption= pikepdf.Encryption(user=pdf_password, owner="USER", allow=no_extr))
#status.set('PDF Protected')
tkinter.messagebox.showinfo("PDF Protector", "PDF Protected and saved in the root folder")
except:
#status.set('Failed to protect')
tkinter.messagebox.showinfo("PDF Protector", "PDF Protection Failed")
window = ttk.Window(themename='darkly')
window.title("Protect PDF || MAF")
window.geometry('650x300')
window.iconbitmap("icon.ico")
input_frame0 = ttk.Frame(master=window)
input_frame1 = ttk.Frame(master=window)
input_frame2 = ttk.Frame(master=window)
input_frame3 = ttk.Frame(master=window)
input_frame4 = ttk.Frame(master=window)
input_frame_space = ttk.Frame(master=window)
location = tk.StringVar()
location_label = ttk.Label(master= input_frame0, text = "PDF LOCATION : ", font= "Poppins 12 bold")
new_pdf_name = tk.StringVar()
new_pdf_name_label = ttk.Label(master= input_frame1, text = "NEW PDF NAME : ", font= "Poppins 12 bold")
password = tk.StringVar()
password_label = ttk.Label(master= input_frame2, text = " SET PASSWORD : ", font= "Poppins 12 bold")
entry = ttk.Entry(master=input_frame0, textvariable= location)
entry1 = ttk.Entry(master=input_frame1, textvariable= new_pdf_name)
entry2 = ttk.Entry(master=input_frame2, textvariable= password)
button = ttk.Button(master=input_frame3, text = "Protect", command= protect)
status = tk.StringVar()
status_label = ttk.Label(master= input_frame2, text = "PDF Protected", font= "Poppins 5", textvariable=status)
input_frame_space.pack(pady= 10)
location_label.pack(side= "left")
entry.pack(side = 'left', padx= 5)
input_frame0.pack(pady=10)
new_pdf_name_label.pack(side= "left")
entry1.pack(side = 'left', padx= 5)
input_frame1.pack(pady= 10)
password_label.pack(side= "left")
entry2.pack(side = 'left', padx= 5)
input_frame2.pack(pady= 10)
button.pack()
input_frame3.pack(pady= 10)
status_label.pack(pady=5)
window.mainloop()