通过python将PPT转换为PNG [英] Convert PPT to PNG via python

查看:96
本文介绍了通过python将PPT转换为PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Python 将 PPT 转换为 png 或其他图像格式.

I want to convert PPT to png, or other image formats using Python.

这个问题已在 SO 上提出,但基本上建议在无头 X 服务器中运行 OpenOffice,我上次使用它时绝对痛苦.(主要是由于 OO 崩溃导致的错误难以复制.)

This question has been asked on SO, but essentially recommends running OpenOffice in headless X server, which was an absolute pain last time I used it. (Mostly due to hard to replicate bugs due to OO crashing.)

还有其他方法吗(希望只使用 Linux CLI 实用程序,并在其上使用纯 Python?)

Is there any other way, (Hopefully using Linux CLI utilities only, and pure Python above them?)

推荐答案

基本工作流程:

  • 使用 PowerPoint 中的 pdf 打印机或 OpenOffice 的内置 PDF 转换器将您的 ppt 转换为 pdf

  • convert your ppt to pdf by using a pdf printer from PowerPoint or OpenOffice's built in PDF converter

使用 ghostscript 将 pdf 转换为 png 或其他图像格式(类似于 gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r100 -sOutputFile=out.png in.pdf)

use ghostscript to convert the pdf to png or other image format (something along the line of gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r100 -sOutputFile=out.png in.pdf)

您可以使用 Python 编写此脚本(并使用 Uno/COM 试用 OOo/MSPP),或您想要的任何脚本.

You can use Python to script this (and pilot OOo / MSPP using Uno / COM), or any script you want.

据我所知,没有处理 PPT 文件或将 PDF 文件转换为 PNG 的 Python 库.

As far as I know, there is no Python library handling PPT files or converting PDF files to PNG.

至于 OOo 崩溃处理,我会在发生此类事件时捕获异常并尝试重新启动 OOo(并且可能跳过该文件,将其添加到需要手动处理的可疑文件列表中).

As for the OOo crash handling, I would catch Exceptions and attempt a restart of OOo when such event occurs (and probably skip the file, adding it to a list of suspicious files requiring manual processing).

您可以找到这篇文章http://www.linuxjournal.com/node/1007788 有趣,因为它提供了一个类,该类使用现有的 OOo 实例以透明方式连接或启动一个实例.它附带了一个 xls -> csv 转换示例(http://www.linuxjournal.com/content/convert-spreadsheets-csv-files-python-and-pyuno),可用作您想要尝试的转换的基础.

You may find this article http://www.linuxjournal.com/node/1007788 interesting as it provides a class which uses an existing OOo instance to connect or launches one if required in a transparent fashion. It comes with an example of xls -> csv conversion (http://www.linuxjournal.com/content/convert-spreadsheets-csv-files-python-and-pyuno) which can be used as a basis for the conversion you want to attempt.

这篇关于通过python将PPT转换为PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆