How to create PowerPoint file using PHP.

Jan 6th, 2015

How to create PowerPoint file using PHP.

Share

Introduction:

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/.

Steps to Setup:
  • 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/’);

include ‘PHPPowerPoint.php’;
include ‘PHPPowerPoint/IOFactory.php’;

Then after, Place below code to start with simple slide.
$objPHPPowerPoint = new PHPPowerPoint();

// block sets slide logo.
$currentSlide = $objPHPPowerPoint->getActiveSlide();
$shape = $currentSlide->createDrawingShape();
$shape->setName(‘PHPPowerPoint logo’);
$shape->setDescription(‘PHPPowerPoint logo’);
$shape->setPath(‘./images/phppowerpoint_logo.gif’);
$shape->setHeight(36);
$shape->setOffsetX(10);
$shape->setOffsetY(10);
$shape->getShadow()->setVisible(true);
$shape->getShadow()->setDirection(45);
$shape->getShadow()->setDistance(10);
// block sets slide logo ends.

// block sets text for first slide.
$shape = $currentSlide->createRichTextShape();
$shape->setHeight(300);
$shape->setWidth(600);
$shape->setOffsetX(170);
$shape->setOffsetY(180);
$shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun(‘Thank you for using PHPPowerPoint!’);
$textRun->getFont()->setBold(true);
$textRun->getFont()->setSize(60);
$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(“Pragma: no-cache”);
header(“Expires: 0”);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Content-Type: application/force-download”);
header(“Content-Type: application/octet-stream”);
header(“Content-Type: application/download”);
header(“Content-Disposition: attachment;filename=” . $newname);
ob_clean();
flush();
readfile($filename);
exit();
// ends.

Source of Inspiration:
http://phppowerpoint.codeplex.com/

Contributors: Monil Patel / Hardik Deliwala.

 

Comments are closed.

Let's Discuss Your Project

Get free consultation and let us know your project idea to turn
it into an amazing digital product.

Let’s talk

NEWS & BLOG

Related Blogs

Why Node.js is Perfect for Enterprise App Development platform ?

Node.js May 1st, 2020

Why Node.js is Perfect for Enterprise App Development p...

Read more
Google chrome to make web apps as powerful as native ones

Android Apps Feb 2nd, 2017

Google chrome to make web apps as powerful as native on...

Read more
4 Reasons to Choose Open source development platforms for web development

Web Sep 16th, 2016

4 Reasons to Choose Open source development platforms f...

Read more

INQUIRY

Let's get in touch

UNITED STATES

31236 Meadowview Square,
Delmar, DE 19940, USA

Sales: +1 667 771 6758

UNITED KINGDOM

13 Layton Road, Hounslow,
London, TW3 1YJ

Sales: +44 7404 607567

INDIA

2nd Floor, Sun Avenue One, Bhudarpura, Ayojan Nagar, Nr. Shyamal Cross Road, Ahmedabad, Gujarat-380006

Sales: +91 635-261-6164

For Project Inquiries

biolah

depo 25 bonus 25 to 5x

depo 25 bonus 25

depo 25 bonus 25

mndrmndr.com

bonusdeposit.net

https://www.greentourstanzania.com/wp-includes/customize/

https://temp1.novotest.biz/id/

depo 25 bonus 25

https://sumberjo-blitar.desa.id/images

https://sumberjo-blitar.desa.id/data

depo 25 bonus 25 to 5x

depo 25 bonus 25

https://www.greentourstanzania.com/wp-includes/js/product/

https://smpabbs.sch.id/gacor/100/

https://smpabbs.sch.id/gacor/bonus/

deposit 25 bonus 25

depo 25 bonus 25

bonus new member 100

https://ppdb.smk-kosgoro.sch.id/data/depo 25 bonus 25https://jesus.nouvellevie.com/wp-includes/images/Getoko.iddepo 25 bonus 25https://bonus-baru.s3.ap-southeast-1.amazonaws.com/link-daftar-slot-gacor.htmlhttps://bonus-baru.s3.ap-southeast-1.amazonaws.com/scatter-pink-paling-gacor.htmlhttps://worldlisteningproject.org/wp-includes/depo25bonus25/bonus new member 100depo 25 bonus 25