Linux 使用 PHP 将 Powerpoint PPT 转换为 JPG 或 PNG 图片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9548755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:58:44  来源:igfitidea点击:

Powerpoint PPT to JPG or PNG Image conversion using PHP

phplinuxpowerpointopenoffice.org

提问by Rob Ganly

I need to convert single Powerpoint (PPT) slides/files to JPG or PNG format on linux but haven't found any way of doing so successfully so far. I have heard that it can be done with open office via php but haven't found any examples or much useful documentation. I'd consider doing it with python or java also, but I'm unsure which route to take.

我需要在 linux 上将单个 Powerpoint (PPT) 幻灯片/文件转换为 JPG 或 PNG 格式,但到目前为止还没有找到任何成功的方法。我听说它可以通过 php 使用 open office 来完成,但还没有找到任何示例或很多有用的文档。我也会考虑用 python 或 java 来做,但我不确定要走哪条路。

I understand that it can be done using COM on a Windows server but would really like to refrain from doing so if possible.

我知道它可以在 Windows 服务器上使用 COM 来完成,但如果可能的话,我真的想避免这样做。

Any ideas/pointers gratefully received. (And yes, I have searched the site and others before posting!)

感谢收到任何想法/指示。(是的,我在发布之前搜索了该网站和其他网站!)

Thanks in advance,

提前致谢,

Rob Ganly

罗布·甘利

回答by Filipi Vianna

Quick answer (2 steps):

快速回答(2步):

## First converts your presentation to PDF
unoconv -f pdf presentation.ppt
## Then convert your PDF to jpg
convert presentation.pdf presentation_%03d.jpg

And voilá.

瞧。

Explaning a little more:

稍微解释一下:

I had already follow in the same need. Convert a powerpoint set of slides into a set of images. I haven't found one tool to exactly this. But I have found unoconv which converts libreoffice formats to other formats, including jpg, png and PDF. The only drawback is that unoconv only converts one slide to a jpg/png file, but when converting to PDF it converts the whole presentation to a multiple page PDF file. So the answare were convert the PPT to PDF and with imagemagick's convert, convert the multiple page PDF to a set of images.

我已经有同样的需求。将一组幻灯片转换为一组图像。我还没有找到一种工具来解决这个问题。但是我发现 unoconv 可以将 libreoffice 格式转换为其他格式,包括 jpg、png 和 PDF。唯一的缺点是 unoconv 只将一张幻灯片转换为 jpg/png 文件,但在转换为 PDF 时,它将整个演示文稿转换为多页 PDF 文件。所以answare将PPT转换为PDF,并使用imagemagick的转换,将多页PDF转换为一组图像。

Unoconv is distributed within Ubuntu distribution

Unoconv 在 Ubuntu 发行版中分发

apt-get install unoconv

And convert is distributed with the imagemagick package

并且 convert 与 imagemagick 包一起分发

apt-get install imagemagick

In my blog there is an entry about this

在我的博客中有一个关于这个的条目

回答by Juan Elias

This can be done from PHP using a 3d party library (Aspose.Slides). It will work on both .ppt and .pptx, and it's lightning fast.

这可以通过 PHP 使用 3d 方库 (Aspose.Slides) 来完成。它适用于 .ppt 和 .pptx,而且速度快如闪电。

Here is the relevant piece of code in PHP:

这是 PHP 中的相关代码段:

$runtime->RegisterAssemblyFromFile("libraries/_bin/aspose/Aspose.Slides.dll", "Aspose.Slides");
$runtime->RegisterAssemblyFromFullQualifiedName("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing");

$sourcefile = "D:\MYPRESENTATION.ppt";

$presentation = $runtime->TypeFromName("Aspose.Slides.Presentation")->Instantiate($sourcefile);
$format = $runtime->TypeFromName("System.Drawing.Imaging.ImageFormat")->Png;

$x = 0;

/** @var \NetPhp\Core\NetProxyCollection */
$slides = $presentation->Slides->AsIterator();

foreach ($slides as $slide) {
  $bitmap = $slide->GetThumbnail(1, 1);
  $destinationfile ="d:\output\slide_{$x++}.png";
  $bitmap->Save($destinationfile, $format);
}

$presentation->Dispose();

It does not use Office Interop (which is NOT recommended for server side automation) and is lightining fast.

它不使用 Office Interop(不推荐用于服务器端自动化)并且速度很快。

You can control the output format, size and quality of the images. Indeed you get a .Net Bitmap object so you can do with it whatever you want.

您可以控制图像的输出格式、大小和质量。实际上,您获得了一个 .Net Bitmap 对象,因此您可以随心所欲地使用它。

The original post is here:

原帖在这里:

http://www.drupalonwindows.com/en/blog/powerpoint-presentation-images-php-drupal-example

http://www.drupalonwindows.com/en/blog/powerpoint-presentation-images-php-drupal-example