用Python制作一个PDF转Word工具

工具:Python3.9.13,VSCode1.73.1,pdf2docx0.5.6,tkinter,Win10Home
PDF文件不易编辑,想要编辑需要转成Word,但网上的工具很多要充VIP,所以今天我们就来做个PDF转Word工具。
首先先安装第三方库:

pip install pdf2docx
pip install tkinter

导入库:

#coding=utf-8
import os
import tkinter
from pdf2docx import parse
from tkinter import filedialog
from tkinter.filedialog import askdirectory
from tkinter import *
from tkinter import ttk
from tkinter.messagebox import *

调用第三方库进行转换和选择文件操作:

pdf_path = ""
_path_ = ""
def selectPath():global _path__path_ = askdirectory()_path_ = _path_.replace("/", "\\")temp2.set(_path_)entry2.configure(textvariable = temp2)
def transPath():_path_ = str(entry2.get())for filename in os.listdir(_path_):if (filename.endswith(".pdf")):global pdf, docxpdf = os.path.join(_path_, filename)docx = pdf[:-4] + '.docx'parse(pdf, docx)showinfo("提示", "转换完成,文件保存在原目录!")
def trans():pdf_file = str(entry1.get())docx_file = pdf_file[:-4] + '.docx'parse(pdf_file, docx_file)showinfo("提示", "转换完成,文件保存在原目录!")
def getPath():temp = tkinter.Tk()temp.withdraw()global pdf_pathpdf_path = filedialog.askopenfilename(title='选择PDF', filetypes=[('PDF Files', '*.pdf'), ('All Files', '*.')])temp1.set(pdf_path)entry1.configure(textvariable = temp1)

最后再搭建GUI界面:

window = tkinter.Tk()
window.title('PDF转Word工具2.0   Powered by 印皓显')
window.geometry('700x450')
# window.resizable (0, 0)
text1 = 'PDF转Word工具'
lb = tkinter.Label(window, text = text1, width=13, height = 1, justify = 'center', anchor = 'nw', font = ('宋体',18), fg = 'white', bg = 'grey', padx = 10, pady = 5)
lb.place(x = 350, y = 25, anchor = "center")
current_work_dir = os.path.dirname(__file__)
img_png = PhotoImage(file = current_work_dir + '\\Pdf转word_clear_compress - 副本.gif') #文件见文末,把图片命名为Pdf转word_clear_compress - 副本.gif再放到代码同目录
label_img = Label(window, image = img_png)
label_img.place(x=180, y=50, anchor='n')
temp1 = StringVar()
entry1 = ttk.Entry(window, textvariable = temp1, width = 36)
entry1.place (x = 375, y = 100, anchor = "nw")
Button1 = ttk.Button(window,text="选择文件",command = getPath)
Button1.place(x = 375, y = 145, anchor = "nw")
Button2 = ttk.Button(window,text="一键转换",command = trans)
Button2.place(x=550, y=145, anchor="nw")
temp2 = StringVar()
entry2 = ttk.Entry(window, textvariable = temp2, width = 36)
entry2.place (x = 375, y = 300, anchor = "nw")
Button3 = ttk.Button(window,text="选择目录",command = selectPath)
Button3.place(x = 375, y = 350, anchor = "nw")
Button4 = ttk.Button(window,text="批量转换",command = transPath)
Button4.place(x = 550, y = 350, anchor = "nw")
window.mainloop()

所有代码:

#coding=utf-8
import os
import tkinter
from pdf2docx import parse
from tkinter import filedialog
from tkinter.filedialog import askdirectory
from tkinter import *
from tkinter import ttk
from tkinter.messagebox import *
pdf_path = ""
_path_ = ""
def selectPath():global _path__path_ = askdirectory()_path_ = _path_.replace("/", "\\")temp2.set(_path_)entry2.configure(textvariable = temp2)
def transPath():_path_ = str(entry2.get())for filename in os.listdir(_path_):if (filename.endswith(".pdf")):global pdf, docxpdf = os.path.join(_path_, filename)docx = pdf[:-4] + '.docx'parse(pdf, docx)showinfo("提示", "转换完成,文件保存在原目录!")
def trans():pdf_file = str(entry1.get())docx_file = pdf_file[:-4] + '.docx'parse(pdf_file, docx_file)showinfo("提示", "转换完成,文件保存在原目录!")
def getPath():temp = tkinter.Tk()temp.withdraw()global pdf_pathpdf_path = filedialog.askopenfilename(title='选择PDF', filetypes=[('PDF Files', '*.pdf'), ('All Files', '*.')])temp1.set(pdf_path)entry1.configure(textvariable = temp1)
window = tkinter.Tk()
window.title('PDF转Word工具2.0   Powered by 印皓显')
window.geometry('700x450')
# window.resizable (0, 0)
text1 = 'PDF转Word工具'
lb = tkinter.Label(window, text = text1, width=13, height = 1, justify = 'center', anchor = 'nw', font = ('宋体',18), fg = 'white', bg = 'grey', padx = 10, pady = 5)
lb.place(x = 350, y = 25, anchor = "center")
current_work_dir = os.path.dirname(__file__)
img_png = PhotoImage(file = current_work_dir + '\\Pdf转word_clear_compress - 副本.gif')
label_img = Label(window, image = img_png)
label_img.place(x=180, y=50, anchor='n')
temp1 = StringVar()
entry1 = ttk.Entry(window, textvariable = temp1, width = 36)
entry1.place (x = 375, y = 100, anchor = "nw")
Button1 = ttk.Button(window,text="选择文件",command = getPath)
Button1.place(x = 375, y = 145, anchor = "nw")
Button2 = ttk.Button(window,text="一键转换",command = trans)
Button2.place(x=550, y=145, anchor="nw")
temp2 = StringVar()
entry2 = ttk.Entry(window, textvariable = temp2, width = 36)
entry2.place (x = 375, y = 300, anchor = "nw")
Button3 = ttk.Button(window,text="选择目录",command = selectPath)
Button3.place(x = 375, y = 350, anchor = "nw")
Button4 = ttk.Button(window,text="批量转换",command = transPath)
Button4.place(x = 550, y = 350, anchor = "nw")
window.mainloop()


最后用auto-py-to-exe打包成exe,再用Inno Setup打包成安装包。(无聊)
安装包下载
安装包:
链接:https://pan.baidu.com/s/1CtOdB9zJKKr2uCVKZtXtgA
提取码:1234
绿色版:
链接:https://pan.baidu.com/s/1pti8YRlGIrJQHUDbNqBQPQ
提取码:1234
(图片获取也可以在绿色版目录下找)

用Python制作一个PDF转Word工具相关推荐

  1. python打字_使用Python制作一个打字训练小工具

    一.写在前面 说道程序员,你会想到什么呢?有人认为程序员象征着高薪,有人认为程序员都是死肥宅,还有人想到的则是996和 ICU. 别人眼中的程序员:飞快的敲击键盘.酷炫的切换屏幕.各种看不懂的字符代码 ...

  2. python 编写实用小工具-使用Python制作一个打字训练小工具

    一.写在前面 说道程序员,你会想到什么呢?有人认为程序员象征着高薪,有人认为程序员都是死肥宅,还有人想到的则是996和 ICU. 别人眼中的程序员:飞快的敲击键盘.酷炫的切换屏幕.各种看不懂的字符代码 ...

  3. 用 Python 制作一个艺术签名小工具,给自己设计一个优雅的签名

    生活中有很多场景都需要我们签字(签名),如果是一些不重要的场景,我们的签名好坏基本无所谓了,但如果是一些比较重要的场景,如果我们的签名比较差的话,就有可能给别人留下不太好的印象了,俗话说字如其人嘛,本 ...

  4. 艺术签名python_用 Python 制作一个艺术签名小工具,给自己设计一个优雅的签名...

    生活中有很多场景都需要我们签字(签名),如果是一些不重要的场景,我们的签名好坏基本无所谓了,但如果是一些比较重要的场景,如果我们的签名比较差的话,就有可能给别人留下不太好的印象了,俗话说字如其人嘛,本 ...

  5. python绘制自己的名字_用 Python 制作一个艺术签名小工具,给自己设计一个优雅的签名...

    生活中有很多场景都需要我们签字(签名),如果是一些不重要的场景,我们的签名好坏基本无所谓了,但如果是一些比较重要的场景,如果我们的签名比较差的话,就有可能给别人留下不太好的印象了,俗话说字如其人嘛,本 ...

  6. 用Python制作一个随机抽奖小工具

    最近在工作中面向社群玩家组织了一场活动,需要进行随机抽奖,参考之前小明大佬的案例,再结合自己的需求,做了一个简单的随机抽奖小工具. 今天我就来顺便介绍一下这个小工具的制作过程吧! 先看效果: 1. 核 ...

  7. python打字效果_Python学习之旅:用Python制作一个打字训练小工具

    一.写在前面 说道程序员,你会想到什么呢?有人认为程序员象征着高薪,有人认为程序员都是死肥宅,还有人想到的则是996和 ICU. Python资源共享群:626017123 别人眼中的程序员:飞快的敲 ...

  8. Python学习之旅:用Python制作一个打字训练小工具

    一.写在前面 说道程序员,你会想到什么呢?有人认为程序员象征着高薪,有人认为程序员都是死肥宅,还有人想到的则是996和 ICU. 别人眼中的程序员:飞快的敲击键盘.酷炫的切换屏幕.各种看不懂的字符代码 ...

  9. 用Python制作一个数据预处理小工具,多种操作,一键完成,非常实用!

    在我们平常使用Python进行数据处理与分析时,在import完一大堆库之后,就是对数据进行预览,查看数据是否出现了缺失值.重复值等异常情况,并进行处理. 本文将结合GUI工具PySimpleGUI, ...

最新文章

  1. Android4.0源码Launcher启动流程分析【android源码Launcher系列一】
  2. 资源在另一个编辑器中打开的错误处理办法
  3. 2013年、2012、2011年中国软件业收入百强名录 看中国软件业这三年的变化
  4. java kotlin lateinit_kotlin - 如何检查“lateinit”变量是否已初始化?
  5. Android应用Activity、Dialog、PopWindow、Toast窗体加入机制及源代码分析
  6. 如果编程语言是女人(译)
  7. 蔬菜大棚成本_蔬菜大棚种植成本和利润究竟如何?种植户有话说
  8. android错误怎么关机,Android系统小技巧:系统崩溃了只重启部分子系统,而不是全部重启...
  9. Linux CentOS7 如何查看占用命令
  10. error500java_错误 500 java.lang.NoClassDefFoundError: com/lowagie/text/pdf/FontMapper
  11. UEFI的诞生与优势
  12. python中pytz库用法详解
  13. lamp一键安装包不安装mysql_LAMP一键安装包-CentOS 5/6下,添加pdo_mysql
  14. 三星手机不能连接无线网络连接服务器,手机已连接wife但无法访问互联网
  15. mflac格式解密_mflac格式是什么意思
  16. 小学计算机考核,小学信息技术学科考核评价方案.docx
  17. c# 接管系统鼠标_4个阶段的方法来接管大型,混乱的IT系统
  18. 爱加密加密Android apk 使用步骤
  19. 序列(sequence)(Python入门十二)
  20. SpringBoot与RocketMQ客户端集成原理解读与示例

热门文章

  1. Oracle导入.dat文件
  2. windows的USB插拔事件日志
  3. wcs系统有哪些模块
  4. DIY 自制700MA多功能台灯+手电筒 (9档功能、低功耗休眠、USB、锂电池供电)
  5. Pivot Table
  6. Bootstrap paddingmargin样式
  7. 油画|艺术|风筝《飞呀飞》
  8. CSS固定定位与粘性定位4大企业级案例
  9. Three Js实现坐标轴
  10. 高考学校老师利用计算机给学生改分,北京高考将实行“3+3”改革方案 文理不再分科...