pdf文件转换成docx工具

import tkinter as tk
from tkinter import filedialog, messagebox
from pdf2docx import Converter


def convert_pdf_to_docx():
    pdf_file = pdf_entry.get()
    docx_file = docx_entry.get()
    cv = Converter(pdf_file)
    cv.convert(docx_file, start=0, end=None)
    cv.close()
    messagebox.showinfo("提示", "文件转换完毕!")
    messagebox.showinfo("提示", f"路径:{docx_file}")


def select_pdf_file():
    pdf_file = filedialog.askopenfilename(initialdir="/", title="Select PDF File",
                                          filetypes=(("PDF Files", "*.pdf"), ("All Files", "*.*")))
    pdf_entry.delete(0, tk.END)
    pdf_entry.insert(tk.END, pdf_file)


def select_docx_file():
    docx_file = filedialog.asksaveasfilename(defaultextension=".docx", filetypes=[("Word Document", "*.docx")])
    docx_entry.delete(0, tk.END)
    docx_entry.insert(tk.END, docx_file)


def exit_program():
    root.destroy()


# 创建主窗口
root = tk.Tk()
root.title("欢迎使用力江PDF转换器")
root.geometry("400x200")

# 创建输入框和按钮
pdf_label = tk.Label(root, text="PDF文件路径:")
pdf_label.place(x=20, y=13.5)
pdf_entry = tk.Entry(root)
pdf_entry.place(x=110, y=13.5)
pdf_button = tk.Button(root, text="选择文件", command=select_pdf_file, bg="#5AAD24")
pdf_button.place(x=265, y=10)

docx_label = tk.Label(root, text="DOCX文件路径:")
docx_label.place(x=10, y=53.5)
docx_entry = tk.Entry(root)
docx_entry.place(x=110, y=53.5)
docx_button = tk.Button(root, text="选择路径", command=select_docx_file, bg="#5EA4CE")
docx_button.place(x=265, y=50)

# 创建转换按钮
convert_button = tk.Button(root, text="开始转换", command=convert_pdf_to_docx, bg="#2AC48C")
convert_button.place(x=100, y=140)

# 创建退出按钮
exit_button = tk.Button(root, text="退出程序", command=exit_program, bg="#FE0000")
exit_button.place(x=230, y=140)

# 运行主循环
root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

力江

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值