How to create PowerPoint file using PHP.
One has to mostly deal with requirement of exporting data to Excel, Word or PDF. Whereas, requirement of exporting data to PowerPoint slides remains as moon in daylight – elusive. Here, We will make ourselves familiar with PowerPoint generation concept using PHP PowerPoint library. Which is available on http://phppowerpoint.codeplex.com/.
- Download zip version of library from http://phppowerpoint.codeplex.com/releases/view/26621
- Extract it and place it to root folder of your Project.
- After extracting folder you will find three sub folders – namely ‘Classes’,’ Documentation’ and ‘Tests’.
- Classes folder contains all magic code to library.
- Test folder holds Sample code for taking first step towards this unknown world.
- Documentation folder has API information.
- Include reference of library by setting up path to library using following two line of code in top of your business logic file from where you are going to start writing your logic.
set_include_path(get_include_path() . PATH_SEPARATOR . ‘../Classes/’);
Then after, Place below code to start with simple slide.
$objPHPPowerPoint = new PHPPowerPoint();
// block sets slide logo.
$currentSlide = $objPHPPowerPoint->getActiveSlide();
$shape = $currentSlide->createDrawingShape();
// block sets slide logo ends.
// block sets text for first slide.
$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’ ) );
// block sets text for first slide ends.
$filename = str_replace(‘.php’, ‘.pptx’, __FILE__);
$newname = “PresentationReport-” . date(‘Y-m-d-H-i-s’) . “.pptx”;
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, ‘PowerPoint2007’);
$objWriter->save(str_replace(‘.php’, ‘.pptx’, __FILE__));
// block to download file.
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Content-Disposition: attachment;filename=” . $newname);
Source of Inspiration:
Contributors: Monil Patel / Hardik Deliwala.
Popular PostsThe Biggest Announcements Made by Apple at WWDC 2020How to Implement Dependency Injection (DI) in Flutter App Development?Important Features to Consider for Building a Food Delivery App like UberEatsWhat Delivery Startups should know about Courier Delivery App DevelopmentYour Guide to Build a Successful On-demand Grocery Delivery App During COVID-19
Google Progressive web apps (PWA) are basically mobile websites that offer the high performance of...
As the process of access to information gets faster and leaner, it gets imperative for...