我现在找出来旧电脑了,脚本如下:
import os
import datetime
import sys
from win32com.client import constants, gencache
def word_to_pdf(wordPath, pdfPath):
# 输入:wordPath文档所在的路径,pdfPath存放PDF的路径
# 功能:将已给wordPath中的.doc和.docx文件生成为.pdf格式的文件,并存放于pdfPath路径下。
print(word_Path)
print(pdf_Path)
# 判断pdfPath路径是否已存在,如若不存在,则创建
if not os.path.exists(pdfPath): # 判断存放PDF的文件夹是否存在
os.makedirs(pdfPath) # 若PDF文件夹不存在就创建
# 遍历wordPath下的.doc和.docx文件,将符合条件的文档进行转换
i = 0
for filename in os.listdir(wordPath):
if os.path.splitext(filename)[1] == '.docx' or os.path.splitext(filename)[1] == '.doc':
i += 1
word_path = wordPath + '\\' + filename
pdf_path = pdfPath + '\\' + os.path.splitext(filename)[0] + '.pdf'
print('正在转换第 {} 个文件:\n {}'.format(i, filename))
try:
word = gencache.EnsureDispatch('Word.Application')
doc = word.Documents.Open(word_path, ReadOnly=1)
doc.ExportAsFixedFormat(pdf_path,
constants.wdExportFormatPDF,
Item=constants.wdExportDocumentWithMarkup,
CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
except Exception as e:
print("转换异常,异常是:{}".format(e))
word.Quit(constants.wdDoNotSaveChanges);
print('本路径下一共有{}个WORD文件'.format(i))
startTime_word2pdf = datetime.datetime.now() # 开始时间
if __name__ == '__main__':
word_Path = sys.argv[1]
pdf_Path = word_Path # 我自己用就不用那么麻烦,直接代码写死在同一个路径下面转换了
word_to_pdf(word_Path, pdf_Path)
word.Quit(constants.wdDoNotSaveChanges);
endTime_word2pdf = datetime.datetime.now() # 结束时间
print('本次WORD转换成PDF格式一共用了:%0.2f秒' % (endTime_word2pdf - startTime_word2pdf).seconds)
# ————————————————
# 版权声明:本文为CSDN博主「米芽在学习」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
# 原文链接:
https://blog.csdn.net/weixin_44834325/article/details/116131453【 在 huhu (水木你好水木再见) 的大作中提到: 】
: 标 题: Re: everything只能搜索文件名是吧?
: 发信站: 水木社区 (Sat Mar 19 22:11:53 2022), 站内
:
: 这个脚本能共享一下么, hiahia
:
: 【 在 AaYaYa (啊呀呀*选帝侯初长成) 的大作中提到: 】
: 本水木BT党党徒是这样做的,给自己的totalcommand添加了一个自定义按钮,按钮内容是自己写的脚本,功能是把当前文件夹下面所有的docx、doc文件批量转换为pdf文件,自己养成习惯,无论何时在做docx文档的时候,查看别人拷给我的docx文档的时候,都顺手先给转成pdf文件,时间长了之后自己电脑里面常用的docx文档基本上就都有pdf版本了,然后在自己常用的PdfXchange Viewer阅读器软件中搜索pdf内容的时候选择一个文件夹路径,就自动搜索该路径下面的所有pdf文件的内容,找到后也就知道了是哪些docx文件里面有我要找的内容了,Xchange Viewer搜索速度不慢
:
: 【 在 chunhui (北瓜) 的大作中提到: 】
: : 标 题: everything只能搜索文件名是吧?
: : 发信站: 水木社区 (Wed Mar 16 11:37:44 2022), 站内
: :
: : 各位如果要全文搜索用什么工具?
: :
: : win11自带的索引实在是个废品。2个小时才索引增加了2个文件。我这台机器都索引了两个星期了,也没弄完。而且一直占cpu 15%左右。一怒之下让我禁用了。
: : --
: :
: : 这不行 那不行 装模作样假惺惺 这就是矫情
: : 对人诚 对己诚 理解包容又热情 这才叫感情
: :
: :
: : 26
: :
: :
: : ※ 来源:·水木社区 mysmth.net·[FROM: 114.249.22.*]
:
:
: --
: 欢迎访问我在二站的个人版:P.AaYaYa
: 不会?很简单,在term中退到主菜单,按k键,再按回车键确定,就来到了二站,然后进入我的个人版面P.AaYaYa
: ※ 来源:·水木社区
http://newsmth.net·[FROM: 143.89.151.*]
:
:
:
:
: --
:
: ※ 来源:·水木社区 mysmth.net·[FROM: 223.104.159.*]
--
FROM 217.69.12.*