• 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数据结构之二叉树的统计与转换实例
  • Python使用稀疏矩阵节省内存实例
  • Ubuntu下创建虚拟独立的Python环境全过程
  • Python类的多重继承问题深入分析
  • 介绍Python的Django框架中的静态资源管理器django-pipeline
  • Windows中使用wxPython和py2exe开发Python的GUI程序的实例教程
  • django 文件上传功能的相关实例代码(简单易懂)
  • python socket多线程通讯实例分析(聊天室)

文章分类

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

最近更新的内容

    • python使用range函数计算一组数和的方法
    • Python黑魔法@property装饰器的使用技巧解析
    • python中快速进行多个字符替换的方法小结
    • python字符串对其居中显示的方法
    • 用实例分析Python中method的参数传递过程
    • python基于urllib实现按照百度音乐分类下载mp3的方法
    • win10系统中安装scrapy-1.1
    • Python的Django框架中的数据库配置指南
    • Python脚本实现集群检测和管理功能
    • Python常见格式化字符串方法小结【百分号与format方法】

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

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