python將word文檔轉pdf文檔

from win32com.client import gencache
from win32com.client import constants, gencache


def createPdf(wordPath, pdfPath):
	"""word轉pdf
	:param wordPath: word文件路徑
	:param pdfPath: 生成pdf文件路徑
	"""
	word = gencache.EnsureDispatch('kwps.Application')  #
	doc = word.Documents.Open(wordPath, ReadOnly=1)
	doc.ExportAsFixedFormat(pdfPath,
	                        constants.wdExportFormatPDF,
	                        Item=constants.wdExportDocumentWithMarkup,
	                        CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
	word.Quit(constants.wdDoNotSaveChanges)


if __name__ == '__main__':
	createPdf(r'D:\test\test001.docx', r'D:\test\test001.pdf')

以上。python

相關文章
相關標籤/搜索