黑松山资源网 Design By www.paidiu.com
本文实例讲述了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.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: 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程序
<!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>项目查重检测系统</title> <style type="text/css"> 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;} </style> <script language=JavaScript> <!-- // function InputCheck(CheckForm) // { // if (CheckForm.projectname.value == "" ) // { // alert("请输入项目名称!"); // CheckForm.projectname.focus(); // return (false); // } // if (document.getElementById("projectsumb").value== "" ) // { // alert("请输入项目简介!"); // CheckForm.projectname.focus(); // return (false); // } } </script> </head> <body> <div> <fieldset> <legend>项目查重检测系统</legend> <form name="CheckForm" method="post" action="index.php" onSubmit="return InputCheck(this)"> <div> <br/> <label for="projectname" class="label">项目名称:</label> <input id="projectname" name="projectname" type="text" style="width: 400px" class="input" /> <divp/> <div> <br/> <label for="projectsumb" class="label">项目简介:</label> <textarea name="projectsumb" id="projectsumb" style="height:400px;width:800px;"></textarea> <div/> <div> <br/> <br/> <input type="submit" name="submit" value=" 检 测 " class="left" /> </div> <div> <br/> <label name="result" class="label">检测结果:</label> <label name="outresult" class="label"></label> <br/> <div/> </form> <br/> <br/> </div> </body> </html> <"GBK","UTF-8"); // $sumb=mb_convert_encoding($_POST['projectsumb'], "GBK","UTF-8"); // $path1="../docTopdf/commFile/test.doc"; $program="D:/Users/Administrator/Anaconda3/python ../docTopdf/DocToPdf/test1.py"; #注意使用绝对路径.$name."".$sumb $output = exec($program) // $output = nl2br(shell_exec($program)); echo mb_convert_encoding ($output,"UTF-8", "GBK"); ?>
更多Python相关内容感兴趣的读者可查看本站专题:《Python文件与目录操作技巧汇总》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》
希望本文所述对大家Python程序设计有所帮助。
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年10月08日
2024年10月08日
- 【原神】V5.0攻略 | 林尼攻略一图流
- 李翊君.1993-相思的烈酒【上华】【WAV+CUE】
- 古巨基.1998-LEO.KU(国)【千禧年代】【WAV+CUE】
- 郭子.2001-原来你什么都不想要创作集丫滚石】【WAV+CUE】
- 《使命召唤:黑色行动6》新预告公布!10月25日发售
- Atlus《暗喻幻想》媒体评分汇总:高分好评如潮!
- 2024金摇杆奖提名揭晓 《黑神话》角逐最佳视觉设计!
- 群星《新说唱2024 第3期 (上)》[320K/MP3][32.76MB]
- 群星《新说唱2024 第3期 (上)》[FLAC/分轨][95.38MB]
- 群星《新说唱2024 第3期 (下)》[320K/MP3][31.36MB]
- 幻兽帕鲁手游什么时候正式上线 最新消息一览
- 西普大陆BOSS位置盘点 解锁天启纪元玩法
- 西普大陆精灵进阶培养攻略 精灵养成指南
- dnf手游法控法系职业哪个强 dnf手游法控法系职业强度排行
- 魔兽世界血藤护目镜图纸在哪买 wlk血藤护目镜图纸购买位置介绍