-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf2txt.py
84 lines (77 loc) · 2.8 KB
/
pdf2txt.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
# Importing Required Modules
import tkinter as tk
import os, time
import pathlib
from PIL import Image,ImageTk
from tkinter.filedialog import askopenfile
from tkinter import messagebox
import PyPDF2
def main():
# Root Window
win = tk.Tk()
win.title("PDF2TXT CONVERTER")
win.geometry('600x400')
win.resizable(False, False)
os.chdir(r'F:\py_projects\Pythonics')
win.wm_iconbitmap('images/bird.ico')
imageBG = ImageTk.PhotoImage(Image.open('images/loginBG.jpg'))
canvas = tk.Canvas(win, width = 600, height = 400)
canvas.create_image(0, 0, anchor = "nw", image = imageBG)
canvas.place_configure(x = 0, y = 0)
tk.Label(win, text = time.ctime(), fg = 'Gold', bg = 'Black', font = 'Helvetica 10').place_configure(x = 440, y = 40)
# Variable Declaring
ch = tk.IntVar()
languages = [
"None",
"PDF2TXT",
"DOCS2PDF"
]
p = 40
# Functions
def optChoice():
opt = ch.get()
if opt == 0:
pass
elif opt == 1:
pass
else:
pass
def openfile():
filetypes = [('*.pdf')]
file = askopenfile(filetypes)
pdf_file = open(file.name, 'rb')
read_pdf = PyPDF2.PdfFileReader(pdf_file)
number_of_pages = read_pdf.getNumPages()
page = read_pdf.getPage(0)
page_content = page.extractText()
pathlib.Path('con_txt.txt').write_text(page_content)
messagebox.showinfo("Done","Successfully Completed.")
# Frame Design
tk.Label(win, text = '*Welcome to PDF2TXT Converter*', fg = 'Red', bg = 'Black', font = 'Helvetica 18 bold').place(x=140,y=10)
tk.Label(win,
text="Choose your Option:",
justify = tk.LEFT,
padx = 20,
fg = "#00FD00",
bg = "Black",
font = 'Helvetica 14 bold'
).place(x = 20, y = 40)
for val, language in enumerate(languages):
p+=30
tk.Radiobutton(win,
text=language,
padx = 20,
variable = ch,
command = optChoice,
value = val,
fg = 'Orange',
bg = 'Black',
font = 'Helvetica 14',
activebackground = "Black"
).place(x = 50, y = p)
tk.Label(win, text = 'Direct path to file:', fg = '#FDFD00', bg = 'Black', font = 'Helvetica 16 bold').place(x = 40, y = 170)
tk.Label(win, text = 'Choose file:', fg = '#FD0DEE', bg = 'Black', font = 'Helvetica 16 bold').place(x = 40, y = 203)
tk.Button(win, text = "Select", width = 30, command = openfile).place(x = 200, y = 200)
win.mainloop()
if __name__ == '__main__':
main()