Python中文
首页
教程
问答
标签
搜索
登录
注册
一种将文档转换为pdf格式的有效方法
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我一直在试图找到有效的方法来将文档(如doc、docx、ppt、pptx)转换为pdf。到目前为止,我已经尝试过<a href="http://documentcloud.github.io/docsplit/">docsplit</a>和<code>oowriter</code>,但都花了>;10秒完成了大小为1.7MB的<a href="http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&cad=rja&ved=0CFIQFjAF&url=http://academy.telerik.com/documents/telerik-academy/csharp-fundamentals/15.%2520Text-Files.pptx&ei=mtLFUoPaHarO4QSAvIGIAg&usg=AFQjCNElUv1xHd4i7-awumeEbLWAqPEyRw&sig2=ubgAa4m7l8hSsDBDLUlDnA&bvm=bv.58187178,d.bGE">pptx file</a>上的任务。有人能给我提个更好的方法或建议来改进我的方法吗?</p> <p>我试过的:</p> <pre><code>from subprocess import Popen, PIPE import time def convert(src, dst): d = {'src': src, 'dst': dst} commands = [ '/usr/bin/docsplit pdf --output %(dst)s %(src)s' % d, 'oowriter --headless -convert-to pdf:writer_pdf_Export %(dst)s %(src)s' % d, ] for i in range(len(commands)): command = commands[i] st = time.time() process = Popen(command, stdout=PIPE, stderr=PIPE, shell=True) # I am aware of consequences of using `shell=True` out, err = process.communicate() errcode = process.returncode if errcode != 0: raise Exception(err) en = time.time() - st print 'Command %s: Completed in %s seconds' % (str(i+1), str(round(en, 2))) if __name__ == '__main__': src = '/path/to/source/file/' dst = '/path/to/destination/folder/' convert(src, dst) </code></pre> <p>输出:</p> <pre><code>Command 1: Completed in 11.91 seconds Command 2: Completed in 11.55 seconds </code></pre> <p>环境:</p> <ul> <li>Linux-Ubuntu 12.04版</li> <li>Python2.7.3</li> </ul> <p>更多工具结果:</p> <ul> <li><a href="http://www.artofsolving.com/opensource/jodconverter">jodconverter</a>花了11.32秒</li> </ul>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>试着从Python代码中调用<a href="http://dag.wiee.rs/home-made/unoconv/">unoconv</a>,在我的本地计算机上用了8秒,我不知道它是否足够快:</p> <pre><code>time unoconv 15.\ Text-Files.pptx real 0m8.604s </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python中两个字典的交集
6 回答
python中两个字符串上的异或操作数?
4 回答
Python中两个字符串中的类似句子
2 回答
Python中两个字符串之间的Hamming距离
8 回答
python中两个字符串之间的匹配模式
1 回答
python中两个字符串之间的按位或
6 回答
python中两个字符串之间的数据(字节)切片
7 回答
python中两个字符串之间的模式
10 回答
python中两个字符串作为子字符串的区别
3 回答
Python中两个字符串元组的比较
9 回答
Python中两个字符串列表中的公共字符串
6 回答
python中两个字符串的Anagram测试
5 回答
Python中两个字符串的正则匹配
10 回答
python中两个字符串的笛卡尔乘积
9 回答
Python中两个字符串相似性的比较
3 回答
python中两个字符串语义相似度的求法
5 回答
Python中两个字符置换成固定长度的字符串,每个字符的数目相等
9 回答
Python中两个对数方程之间的插值和平滑数据
5 回答
Python中两个对象之间的And/Or运算符
5 回答
python中两个嵌套字典中相似键的和值
9 回答