{"id":20205,"date":"2015-01-06T07:47:41","date_gmt":"2015-01-06T13:17:41","guid":{"rendered":"https:\/\/www.solutionanalysts.com\/blog\/how-to-create-powerpoint-file-using-php\/"},"modified":"2023-08-16T23:01:16","modified_gmt":"2023-08-17T04:31:16","slug":"how-to-create-powerpoint-file-using-php","status":"publish","type":"post","link":"https:\/\/www.solutionanalysts.com\/blog\/how-to-create-powerpoint-file-using-php\/","title":{"rendered":"How to create PowerPoint file using PHP."},"content":{"rendered":"<div>\n<div>\n<div style=\"text-align: justify;\">\n<div style=\"text-align: left;\"><b><u>Introduction:<\/u><\/b><\/div>\n<\/div>\n<\/div>\n<div>\n<div style=\"text-align: justify;\">\n<p>One has to mostly deal with \u00a0requirement of exporting data to Excel, Word or PDF. Whereas, requirement of exporting data to PowerPoint slides remains as moon in daylight &#8211; elusive. Here, We will make ourselves familiar with PowerPoint generation concept using PHP PowerPoint library. Which is available on\u00a0<a href=\"http:\/\/phppowerpoint.codeplex.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/phppowerpoint.codeplex.com\/<\/a>.<\/p>\n<\/div>\n<\/div>\n<div>\n<div style=\"text-align: justify;\">\n<div><u>Steps to Setup:<\/u><\/div>\n<div>\n<div>\n<div style=\"text-align: left;\"><\/div>\n<\/div>\n<div>\n<ul>\n<li>Download zip version of library from\u00a0<a href=\"http:\/\/phppowerpoint.codeplex.com\/releases\/view\/26621\" target=\"_blank\" rel=\"noopener\">http:\/\/phppowerpoint.codeplex.com\/releases\/view\/26621<\/a><\/li>\n<li>Extract it and place it to root folder of your Project.<\/li>\n<li>After extracting folder you will find three sub folders &#8211; namely \u2018Classes\u2019,\u2019 Documentation\u2019 and \u2018Tests\u2019.\n<ul>\n<li>Classes folder contains all magic code to library.<\/li>\n<li>Test folder holds Sample code for taking first step towards this unknown world.<\/li>\n<li>Documentation folder has API information.<\/li>\n<\/ul>\n<\/li>\n<li>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.<\/li>\n<\/ul>\n<p>set_include_path(get_include_path() . PATH_SEPARATOR . &#8216;..\/Classes\/&#8217;);<\/p>\n<p>include &#8216;PHPPowerPoint.php&#8217;;<br \/>\ninclude &#8216;PHPPowerPoint\/IOFactory.php&#8217;;<\/p>\n<p>Then after, Place below code to start with simple slide.<br \/>\n$objPHPPowerPoint = new PHPPowerPoint();<\/p>\n<p>\/\/ block sets slide logo.<br \/>\n$currentSlide = $objPHPPowerPoint-&gt;getActiveSlide();<br \/>\n$shape = $currentSlide-&gt;createDrawingShape();<br \/>\n$shape-&gt;setName(&#8216;PHPPowerPoint logo&#8217;);<br \/>\n$shape-&gt;setDescription(&#8216;PHPPowerPoint logo&#8217;);<br \/>\n$shape-&gt;setPath(&#8216;.\/images\/phppowerpoint_logo.gif&#8217;);<br \/>\n$shape-&gt;setHeight(36);<br \/>\n$shape-&gt;setOffsetX(10);<br \/>\n$shape-&gt;setOffsetY(10);<br \/>\n$shape-&gt;getShadow()-&gt;setVisible(true);<br \/>\n$shape-&gt;getShadow()-&gt;setDirection(45);<br \/>\n$shape-&gt;getShadow()-&gt;setDistance(10);<br \/>\n\/\/ block sets slide logo ends.<\/p>\n<p>\/\/ block sets text for first slide.<br \/>\n$shape = $currentSlide-&gt;createRichTextShape();<br \/>\n$shape-&gt;setHeight(300);<br \/>\n$shape-&gt;setWidth(600);<br \/>\n$shape-&gt;setOffsetX(170);<br \/>\n$shape-&gt;setOffsetY(180);<br \/>\n$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );<br \/>\n$textRun = $shape-&gt;createTextRun(&#8216;Thank you for using PHPPowerPoint!&#8217;);<br \/>\n$textRun-&gt;getFont()-&gt;setBold(true);<br \/>\n$textRun-&gt;getFont()-&gt;setSize(60);<br \/>\n$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( &#8216;FFC00000&#8217; ) );<br \/>\n\/\/ block sets text for first slide ends.<\/p>\n<p>$filename = str_replace(&#8216;.php&#8217;, &#8216;.pptx&#8217;, __FILE__);<br \/>\n$newname = &#8220;PresentationReport-&#8221; . date(&#8216;Y-m-d-H-i-s&#8217;) . &#8220;.pptx&#8221;;<br \/>\n$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, &#8216;PowerPoint2007&#8217;);<br \/>\n$objWriter-&gt;save(str_replace(&#8216;.php&#8217;, &#8216;.pptx&#8217;, __FILE__));<\/p>\n<p>\/\/ block to download file.<br \/>\nheader(&#8220;Pragma: no-cache&#8221;);<br \/>\nheader(&#8220;Expires: 0&#8221;);<br \/>\nheader(&#8220;Cache-Control: must-revalidate, post-check=0, pre-check=0&#8221;);<br \/>\nheader(&#8220;Content-Type: application\/force-download&#8221;);<br \/>\nheader(&#8220;Content-Type: application\/octet-stream&#8221;);<br \/>\nheader(&#8220;Content-Type: application\/download&#8221;);<br \/>\nheader(&#8220;Content-Disposition: attachment;filename=&#8221; . $newname);<br \/>\nob_clean();<br \/>\nflush();<br \/>\nreadfile($filename);<br \/>\nexit();<br \/>\n\/\/ ends.<\/p>\n<p><strong>Source of Inspiration:<\/strong><br \/>\nhttp:\/\/phppowerpoint.codeplex.com\/<\/p>\n<p><b style=\"color: #666666; font-size: 13.008px; line-height: 1.538em;\">Contributors:\u00a0<\/b><span style=\"font-size: 13.008px; line-height: 1.538em;\">Monil Patel \/\u00a0<\/span><span style=\"font-size: 13.008px; line-height: 1.538em;\">Hardik Deliwala.<\/span><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One has to mostly deal with \u00a0requirement of exporting data to Excel, Word or PDF.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129],"tags":[],"class_list":["post-20205","post","type-post","status-publish","format-standard","hentry","category-web"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/20205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/comments?post=20205"}],"version-history":[{"count":1,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/20205\/revisions"}],"predecessor-version":[{"id":32641,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/20205\/revisions\/32641"}],"wp:attachment":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/media?parent=20205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/categories?post=20205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/tags?post=20205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}