代码(Anaconda终端下)python
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn pywin32
运行结果
web
在pycharm中输入代码svg
from win32com.client import Dispatch, constants, gencache # 放入要转换的word格式路径 docx_path = 'G:\示例.docx' # 放入要导出的pdf格式的路径,而且命名 pdf_path = 'G:\示例.pdf' # 转换 gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4) wd = Dispatch('Word.Application') doc = wd.Documents.Open(docx_path, ReadOnly=1) doc.ExportAsFixedFormat(pdf_path, constants.wdExportFormatPDF, Item=constants.wdExportDocumentWithMarkup, CreateBookmarks=constants.wdExportCreateHeadingBookmarks) wd.Quit(constants.wdDoNotSaveChanges)
docx文件
pdf文件
我的感受pdf版本的真的看起来好舒服呀ui
代码(Anaconda终端下)spa
pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple/ docx2pdf
如图所示
code
from docx2pdf import convert import os #''放入你想要转换的文件路径 director = r'G:\eg' FileList = map(lambda x: director + '\\' + x, os.listdir('G:\eg')) for file in FileList: convert(file, f"{file.split('.')[0]}.pdf")
这就是所有内容啦,但愿能够帮到你熬!orm