Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert ppt slide to jpeg images in php

I saw some similar questions on this forum but all those were for .NET platform so please don't close it as duplicate. I have a linux system and I want to convert slide to images via php or shell script(less preferable). the convert command can convert pdf to jpg's but not a ppt.

Any help would be great.

like image 796
prongs Avatar asked Jan 04 '12 18:01

prongs


People also ask

How do I convert PowerPoint slide to JPEG?

Click to open the Save as Type drop-down menu. Select one of the following image formats for your slide. Click Save. Review the PowerPoint dialog box, and select Just This One to save your selected slide as an image.

Can we convert the designed slide in PowerPoint to JPEG?

Change the "Save as Type" from PowerPoint Presentation to JPEG File Interchangeable Format. You will see a drop down list of file types to convert to. Scroll to the JPEG format and select it. Select the folder to save the presentation in.

Can you export a PowerPoint slide as an image?

Step 2: Export the slide as a picture In PowerPoint, open your slide presentation, and then open the slide that you want to export. On the File menu, select Save As. In the Save as type box, select one of the following picture formats: GIF Graphics Interchange Format (.


2 Answers

I was able to accomplish this by first converting the powerpoint file to pdf. This required me installing libre office on my server. Then converting the pdf to images is easily done using image magic. Here is some of my code. It uses https://github.com/ncjoes/office-converter (for the ppt to pdf conversion) and https://github.com/spatie/pdf-to-image (for the pdf to image conversion)

  //now convert file to pdf
            $converter = new OfficeConverter($newFile);
            $result = $converter->convertTo('output.pdf');

            $pdfFile = BASE_PATH.'/output.pdf';
            //now convert pdf file to images
            chdir(BASE_PATH); 

            //get total number of pages in pdf file
            $pdf = new \Spatie\PdfToImage\Pdf($pdfFile);
            $pdf->setCompressionQuality(80);
            $pages = $pdf->getNumberOfPages();

            for($i=1;$i<=$pages;$i++){
                $pdf->setPage($i)->saveImage(BASE_PATH."/image$i.jpg");

            }
like image 192
Ayokunle Akinboboye Avatar answered Sep 24 '22 07:09

Ayokunle Akinboboye


http://code.google.com/p/jodconverter/ seems to have all the building blocks in place, there is even a sample webapp.

We used the old version at http://sourceforge.net/projects/jodconverter/ successfully some time ago, but thI really can't remember the details.

like image 43
Eugen Rieck Avatar answered Sep 25 '22 07:09

Eugen Rieck