• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python实现将DOC文档转换为PDF的方法

Python实现将DOC文档转换为PDF的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python doc,python doc gensim,python 读取doc,python读取doc文件,python doc string等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python实现将DOC文档转换为PDF的方法。分享给大家供大家参考。具体实现方法如下:

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)

</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python实现将DOC文档转换为PDF的方法
  • Python实现将DOC文档转换为PDF的方法
  • python访问类中docstring注释的实现方法

相关文章

  • python获取指定路径下所有指定后缀文件的方法
  • 不要用强制方法杀掉python线程
  • 一个超级简单的python web程序
  • python集合类型用法分析
  • 实例探究Python以并发方式编写高性能端口扫描器的方法
  • 在Python中使用zlib模块进行数据压缩的教程
  • python发布模块的步骤分享
  • Django与遗留的数据库整合的方法指南
  • Python中列表和元组的使用方法和区别详解
  • 连接Python程序与MySQL的教程

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python ftp上传文件
    • Python中List.index()方法的使用教程
    • Python Property属性的2种用法
    • Python基础之函数用法实例详解
    • python base64 decode incorrect padding错误解决方法
    • Python动态加载模块的3种方法
    • 在Python的Django框架上部署ORM库的教程
    • Python提示[Errno 32]Broken pipe导致线程crash错误解决方法
    • 简述Python中的进程、线程、协程
    • python爬虫入门教程之点点美女图片爬虫代码分享

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有