How to convert ppt slide to jpeg images in php

prongs picture prongs · Jan 4, 2012 · Viewed 7.8k times · Source

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.

Answer

Ayokunle Akinboboye picture Ayokunle Akinboboye · Apr 24, 2019

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");

            }