-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDF2IMG_GUI.py
44 lines (34 loc) · 1.27 KB
/
PDF2IMG_GUI.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
import os
import tkinter as tk
from tkinter import filedialog
from pdf2image import convert_from_path
import subprocess
import time
def select_pdf_file():
file_path = filedialog.askopenfilename(filetypes=[("PDF Files", "*.pdf")])
if file_path:
pdf_to_images(file_path)
def pdf_to_images(pdf_path):
dpi = 300
# Get the user's desktop directory
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
# Ensure the output folder exists, create it if not
output_folder = os.path.join(desktop_path, "PDFConversionOutput")
if not os.path.exists(output_folder):
os.makedirs(output_folder)
base_name = os.path.splitext(os.path.basename(pdf_path))[0]
timestamp = time.strftime("%Y%m%d%H%M%S")
output_file = f'{base_name}_{timestamp}'
fmt = 'png'
convert_from_path(pdf_path, dpi=dpi, output_folder=output_folder, output_file=output_file, fmt=fmt)
open_output_folder(output_folder)
def open_output_folder(folder_path):
try:
subprocess.Popen(["explorer", folder_path])
except Exception as e:
print("Failed to open folder:", e)
app = tk.Tk()
app.title("PDF to Image Converter")
select_button = tk.Button(app, text="Select PDF File", command=select_pdf_file)
select_button.pack(pady=20)
app.mainloop()