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
| import tkinter as tk from tkinter import filedialog import subprocess import os import ctypes import math
def set_dpi_awareness(): ctypes.windll.shcore.SetProcessDpiAwareness(1) return ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100
def convert_files(): file_paths = filedialog.askopenfilenames( filetypes=[("PDF Files", "*.pdf")], title="选择一个或多个PDF文件" ) if not file_paths: status_label.config(text="未选择文件", fg="black") return status_label.config(text="转换中,请稍候...", fg="red") root.update() successful_conversions = 0 converted_files = [] for file_path in file_paths: file_name = os.path.basename(file_path) converted_files.append(file_name) command = ["inkscape.exe", "--pdf-font-strategy=substitute", "--export-type=emf", file_path] try: successful_conversions += 1 status_label.config(text=f"正在转换文件 {file_name}", fg="purple") subprocess.run(command, check=True) root.update() except subprocess.CalledProcessError: status_label.config(text=f"转换文件 {file_name} 失败", fg="red") root.update() status_label.config(text=f"已经成功转换 {successful_conversions} 个文件", fg="green") converted_files_label.config(text="成功转换的 PDF 文件:\n" + "\n".join(converted_files))
def main(): global root, status_label, converted_files_label root = tk.Tk() root.title("PDF 转换工具") scale_factor = set_dpi_awareness() root.tk.call('tk', 'scaling', scale_factor) title_font_size = math.ceil(14 * scale_factor) normal_font_size = math.ceil(12 * scale_factor) title_font = ("SimHei", title_font_size, "bold") normal_font = ("SimHei", normal_font_size) window_width = int(600 * scale_factor) window_height = int(600 * scale_factor) root.geometry(f"{window_width}x{window_height}") label = tk.Label(root, text="请选择要转换成 EMF 格式的 PDF 文件", font=title_font) label.pack(pady=20)
convert_button = tk.Button(root, text="选择文件并转换", command=convert_files, font=normal_font) convert_button.pack(pady=20) status_label = tk.Label(root, text="", font=normal_font) status_label.pack(pady=20) converted_files_label = tk.Label(root, text="", font=normal_font) converted_files_label.pack(pady=20)
root.mainloop()
if __name__ == "__main__": main()
|