Powerpoint PPT to JPG or PNG Image conversion using PHP
Asked Answered
D

2

6

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.

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

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

Thanks in advance,

Rob Ganly

Diamagnet answered 3/3, 2012 at 18:37 Comment(0)
S
17

Quick answer (2 steps):

## 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 is distributed within Ubuntu distribution

apt-get install unoconv

And convert is distributed with the imagemagick package

apt-get install imagemagick

In my blog there is an entry about this

Shuping answered 16/4, 2013 at 19:26 Comment(3)
convert properly did the conversion, nevertheless the unoconv failed in the pixel-perfect format. Must say mine was a pptx renamed to ppt so unoconv reads it - IDK if that is the source of the problem, temporarily did the pptx to pdf export manually and then had imagemagick's convert to do the rest.Patronize
I think the problem with unoconv is not being able to do a good font-substitution. Opened a related question here: askubuntu.com/questions/589799/…Patronize
How do you avoid losing quality, when converting from pdf to png?Wainscoting
A
1

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.

Here is the relevant piece of code in 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.

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.

The original post is here:

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

Anderer answered 31/1, 2016 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.