最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)將DOC文檔轉(zhuǎn)換為PDF的方法

 更新時間:2015年07月25日 10:15:05   作者:Sephiroth  
這篇文章主要介紹了Python實(shí)現(xiàn)將DOC文檔轉(zhuǎn)換為PDF的方法,涉及Python調(diào)用系統(tǒng)win32com組件實(shí)現(xiàn)文件格式轉(zhuǎn)換的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了Python實(shí)現(xiàn)將DOC文檔轉(zhuǎn)換為PDF的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

import sys, os
from win32com.client import Dispatch, constants, gencache
def usage():
  sys.stderr.write ("doc2pdf.py input [output]")
  sys.exit(2)
def doc2pdf(input, output):
 w = Dispatch("Word.Application")
 try:
  doc = w.Documents.Open(input, ReadOnly = 1)
  doc.ExportAsFixedFormat(output, constants.wdExportFormatPDF,
   Item = constants.wdExportDocumentWithMarkup, CreateBookmarks = constants.wdExportCreateHeadingBookmarks)
  return 0
 except:
  return 1
 finally:
  w.Quit(constants.wdDoNotSaveChanges)
# Generate all the support we can.
def GenerateSupport():
 # enable python COM support for Word 2007
 # this is generated by: makepy.py -i "Microsoft Word 12.0 Object Library"
 gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4)
def main():
 if (len(sys.argv) == 2):
  input = sys.argv[1]
  output = os.path.splitext(input)[0]+'.pdf'
 elif (len(sys.argv) == 3):
  input = sys.argv[1]
  output = sys.argv[2]
 else:
  usage()
 if (not os.path.isabs(input)):
  input = os.path.abspath(input)
 if (not os.path.isabs(output)):
  output = os.path.abspath(output)
 try:
  GenerateSupport()
  rc = doc2pdf(input, output)
  return rc
 except:
  return -1
if __name__=='__main__':
  rc = main()
  if rc:
    sys.exit(rc)
  sys.exit(0)

希望本文所述對大家的Python程序設(shè)計有所幫助。

相關(guān)文章

最新評論

九龙县| 囊谦县| 绥中县| 米脂县| 陇西县| 靖西县| 定襄县| 太白县| 靖州| 容城县| 扬州市| 玉山县| 屯留县| 奇台县| 元朗区| 临江市| 安平县| 庆城县| 福泉市| 隆安县| 樟树市| 宁晋县| 远安县| 铁岭市| 托里县| 东宁县| 江孜县| 余干县| 福鼎市| 宜昌市| 泾川县| 临澧县| 论坛| 响水县| 田林县| 林周县| 崇明县| 苍梧县| 临高县| 银川市| 临沂市|