原理
使用python win32 庫 調用word底層vba,將word轉成pdf
安裝pywin32
pip install pywin32
python代碼
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('Word.Application') doc = word.Documents.Open(wordPath, ReadOnly=1) doc.ExportAsFixedFormat(pdfPath, constants.wdExportFormatPDF, Item=constants.wdExportDocumentWithMarkup, CreateBookmarks=constants.wdExportCreateHeadingBookmarks) word.Quit(constants.wdDoNotSaveChanges)
工欲善其事,必先利其器!
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。