欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python word轉(zhuǎn)pdf代碼實例

 更新時間:2019年08月16日 08:32:35   作者:jokerB  
這篇文章主要介紹了python word轉(zhuǎn)pdf代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

原理

使用python win32 庫 調(diào)用word底層vba,將word轉(zhuǎn)成pdf

安裝pywin32

pip install pywin32 

python代碼

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

def createPdf(wordPath, pdfPath):
  """
  word轉(zhuǎn)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)

工欲善其事,必先利其器!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論