-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdftoword.py
71 lines (47 loc) · 2.23 KB
/
pdftoword.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
import tkinter as tk
from tkinter import filedialog
from pdf2docx import Converter
def convert_pdf_to_docx(pdf_path, docx_path):
obj = Converter(pdf_path)
obj.convert(docx_path)
obj.close()
class PDFToWordApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("PDF to Word Converter")
self.geometry("600x200")
# Widgets
tk.Label(self, text="Select PDF file:").grid(row=0, column=0, padx=10, pady=10)
self.pdf_entry = tk.Entry(self, width=40)
self.pdf_entry.grid(row=0, column=1, padx=10, pady=10)
tk.Button(self, text="Browse", command=self.browse_pdf).grid(row=0, column=2, padx=10, pady=10)
tk.Label(self, text="Select output DOCX file:").grid(row=1, column=0, padx=10, pady=10)
self.docx_entry = tk.Entry(self, width=40)
self.docx_entry.grid(row=1, column=1, padx=10, pady=10)
tk.Button(self, text="Browse", command=self.browse_output_folder).grid(row=1, column=2, padx=10, pady=10)
tk.Button(self, text="Convert", command=self.convert_pdf).grid(row=2, column=0, columnspan=3, pady=20)
self.result_label = tk.Label(self, text="")
self.result_label.grid(row=3, column=0, columnspan=3)
def browse_output_folder(self):
folder_path = filedialog.asksaveasfilename(defaultextension=".docx", filetypes=[("Word files", "*.docx")])
self.docx_entry.delete(0, tk.END)
self.docx_entry.insert(0, folder_path)
def browse_pdf(self):
file_path = filedialog.askopenfilename(filetypes=[("PDF files", "*.pdf")])
self.pdf_entry.delete(0, tk.END)
self.pdf_entry.insert(0, file_path)
def convert_pdf(self):
pdf_path = self.pdf_entry.get()
docx_path = self.docx_entry.get()
if pdf_path and docx_path:
convert_pdf_to_docx(pdf_path, docx_path)
self.result_label.config(text="Conversion completed successfully!")
else:
self.result_label.config(text="Please select PDF and output DOCX paths.")
def main_pdftoword():
app = PDFToWordApp()
app.mainloop()
# Run the GUI
if __name__ == "__main__":
app = PDFToWordApp()
app.mainloop()