# -*- coding: UTF8 -*-
from win32com.client import *
def switch_pdf(path, name):
'''
作用:将word文档转化为pdf文档
参数1:文件夹路径
参数2:文件名
'''
# 创建word程序对象
word = gencache.EnsureDispatch('Word.Application')
# 读取word文件
f = word.Documents.Open(path + name)
# 转化为word文件
f.ExportAsFixedFormat(path + "hello.pdf", constants.wdExportFormatPDF)
# 退出程序
word.Quit();
switch_pdf("C:\\Users\\Administrator\\Desktop\\word文档\\" , "hello.doc")

运行效果图:

打开网易新闻 查看更多图片

原 word 样式:

新 pdf 样式:

打开网易新闻 查看更多图片

ExportAsFixedFormat() 转化方法的参数使用详情:

喜欢的点个赞吧!