People following me on Twitter could have already guessed, but here’s something I probably should not have done for my agenda: next to the well known PHPExcel class library, I’ve now also started something similar for PowerPoint: PHPPowerPoint.
Just like with PHPExcel, PHPPowerPoint can be used to generate PPTX files from a PHP application. This can be done by creating an in-memory presentation that consists of slides and different shapes, which can then be written to disk using a writer (of which there’s currently only one for PowerPoint 2007).
Here’s some sample code:
/* Create new PHPPowerPoint object */
$objPHPPowerPoint = new PHPPowerPoint();
/* Create slide */
$currentSlide = $objPHPPowerPoint->getActiveSlide();
/* Create a shape (drawing) */
$shape = $currentSlide->createDrawingShape();
/* Create a shape (text) */
$shape = $currentSlide->createRichTextShape();
$shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
$textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FFC00000' ) );
/* Save PowerPoint 2007 file */
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$objWriter->save(str_replace('.php', '.pptx', __FILE__));
A more advanced sample is also included in the download, where a complete presentation is rendered using PHPPowerPoint.
Now go grab the fresh sample on CodePlex and be the very first person downloading and experimenting with it. Feel free to post some feature requests or general remarks on CodePlex too.
This is an imported post. It was imported from my old blog using an automated tool and may contain formatting errors and/or broken images.