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><a href="http://johnmacfarlane.net/pandoc/" rel="nofollow">Pandoc</a>是一个很好的工具,能够快速完成您想要的任务。由于您使用Popen来有效地为该工具发出命令,所以该工具使用什么语言编写并不重要(Pandoc是用Haskell编写的)。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
6 回答
Jupyter运行不同版本的卸载库?
4 回答
Jupyter运行指定的键盘快捷键
10 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
4 回答
Jupyter重新加载自定义样式
4 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
1 回答
jupyter错误:无法在随机林中将决策树视为png
3 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
7 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
5 回答
Jupyter隐藏数据帧索引,但保留原始样式
4 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
7 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
4 回答
Jupy上Python的读/写访问问题
10 回答
jupy上没有模块cv
8 回答
Jupy上的排序错误
8 回答
Jupy中bqplot图形的紧凑布局
7 回答
Jupy中matplotlib plot的连续更新
8 回答
Jupy中Numpy函数的文档
9 回答
Jupy中Pandas的自动完成问题
4 回答
jupy中Qt后端的Matplotlib动画
8 回答