• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python实现将doc转化pdf格式文档的方法

python 搞代码 4年前 (2022-01-08) 19次浏览 已收录 0个评论

这篇文章主要介绍了Python实现将doc转化pdf格式文档的方法,结合实例形式分析了Python实现doc格式文件读取及转换pdf格式文件的操作技巧,以及php调用py文件的具体实现方法,需要的朋友可以参考下

本文实例讲述了Python实现将doc转化pdf格式文档的方法。分享给大家供大家参考,具体如下:

 #-*- coding:utf-8 -*- # doc2pdf.py: python script to convert doc to pdf with bookmarks! # Requires Office 2007 SP2 # Requires python for win32 extension import sys, os from win32com.client import Dispatch, constants, gencache 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(): print(len(sys.argv)) if (len(sys.arg<strong style="color:transparent">来源gao@daima#com搞(%代@#码@网</strong>v) == 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: input = u'BA06007013.docx'#word文档的名称 output = u'BA06007013.pdf'#pdf文档的名称 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__': print("hello") rc = main() if rc: sys.exit(rc) sys.exit(0) 

php调用py程序

   <title>项目查重检测系统</title> html{font-size:16px;} fieldset{width:1080px; margin: 0 auto;} legend{font-weight:bold; font-size:14px;} label{float:left; width:120px; margin-left:10px;} .left{margin-left:120px;} .input{width:150px;} span{color: #666666;}  <div> <fieldset> <legend>项目查重检测系统</legend> <div> <br /><label for="projectname" class="label">项目名称:</label><div> <br /><label for="projectsumb" class="label">项目简介:</label><textarea name="projectsumb" id="projectsumb" style="height:400px;width:800px"></textarea><div /><div> <br /><br /></div><div> <br /><label class="label">检测结果:</label><label class="label"></label><br /><div /><br /><br /></div>  

更多Python相关内容感兴趣的读者可查看本站专题:《Python文件与目录操作技巧汇总》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》

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

以上就是Python实现将doc转化pdf格式文档的方法的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python实现将doc转化pdf格式文档的方法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址