Dec 2, 2010 at 5:31 AM



I am looking for solutions to the below problems .

1.  Is it possible to force download the pptx file after it gets created?  Please give the sample code to do it and where to modify to do so.

2.  The data that has to be in the pptx files is from database,  Is it possible to create slides automatically when the content exceeds the slide space?

3.  I want to directly pass HTML text. like createText->("HI i want \n This goes to 2nd line")






Dec 2, 2010 at 7:41 AM

Download the library and have a look at the test samples, they've got everything you need in there.  It does not handle HTML or automatically create new slides for you, you'll have to code that yourself.


Dec 4, 2010 at 1:30 PM

Thanks for your reply,


I went through the examples.  But, could not find the code/example for forcedownloading.  Tried using header() without luck.  It would be useful if you give sample code for it.



Dec 6, 2010 at 9:22 AM


Here's an extension of the 01simple.php example to force download of the file:


$objPHPPowerPoint = new PHPPowerPoint();
$objPHPPowerPoint->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 PPTX Test Document")
->setSubject("Office 2007 PPTX Test Document")
->setDescription("Test document for Office 2007 PPTX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
$currentSlide = $objPHPPowerPoint->getActiveSlide();
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPowerPoint logo')
->setDescription('PHPPowerPoint logo')
$shape = $currentSlide->createRichTextShape()
$shape->getActiveParagraph()->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
->setColor( new PHPPowerPoint_Style_Color( 'FFC00000' ) );
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$filename = str_replace('.php', '.pptx', __FILE__);
// force download of pptx 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=".$filename);

I've not fully tested but should do the trick.


Dec 9, 2010 at 11:09 PM

Thanks once again,


Its working fine.


One more thing,  I am getting all the data from database.  Is there anyway of detecting when the text height is reached the end of the slide?  So, that i can insert a new slide

and continue.



Dec 10, 2010 at 8:40 AM

Good stuff.

On the text height thing, that's really not straightforward and I've not found anything that could do this for me within the library.  At the moment I just calculate a rough estimate in height based on a fixed width and the number of letters that can fit in each line.  However this doesn't work if you've got line breaks, bullet points and images within the text.  As my requirements are quite simple I've not developed it further.

Please do share if you find anything that can do this accurately as I'm sure it'll be useful at some point.


Apr 7, 2011 at 3:27 PM

hi shivam0101f and chengster..
forgive my ignorance but i was trying to do the same thing. and it's working..but now i have a problem  and i need to know, if you know who insert a image from database to 01simple.php... i estimate your help!..thank's..

Apr 7, 2011 at 3:37 PM


I think you are asking how to insert an image into the ppt?  Sorry, your question isn't very clear.


Apr 7, 2011 at 4:03 PM

yes  that my question , but my image comes from my database, and i dont know how apply..

please i need your help..

Apr 7, 2011 at 4:06 PM

When you say it's in your database, do you mean you're storing a file reference to an image or actually storing the image in binary in the database?


Apr 7, 2011 at 4:17 PM
Edited Apr 7, 2011 at 4:42 PM


hi steve

 yes I mean that my images are stored in binary.

I leave you my e-mail if you want to be more in touch please ..
I need your help ....


Apr 7, 2011 at 4:57 PM
On 07/04/2011 17:17, newkeny wrote:
> I mean that my images are stored in binary.
In that case, take a look at the 04inmemoryimage.php script in /Tests.

This takes an image as a PHP string (as might be retrieved from a
database) and adds it to a slide using the
PHPPowerPoint_Shape_MemoryDrawing class.

Mark Baker
Apr 7, 2011 at 5:37 PM

Hi MarkBaker...

thank's for your help!.. :)

ok. let me take a look

i really need help..

if you if you can show me how... will do.. please.. 

in the meantime let me take a look..

Apr 8, 2011 at 9:53 AM

Hi Alexander,

There are quite a few examples within the tests folder, if you run through all of them you'll soon realise what you can achieve with this library.  To achieve your own desired outcome will depend on your own logic and ability to program.

Good luck!


Apr 8, 2011 at 3:19 PM

Hi Steve.

Thanks for the above. I am a beginner but eager to grow in this area
and if not get help from other developers .... how to grow ...
even so ... take into account your comments and continue to do my tests from test files........


Apr 8, 2011 at 4:29 PM

I totally understand your predicament, I was once there too many moons back and yes, you will learn from other developers... however, I cannot speak for all developers, but most have a lot on their plate and will not likely write a solution for you hence the sample code that's provided in the tests folder.... if I had done something along the lines as what you require I would've posted my code by now... but since I've not I'm afraid I cannot help you right now... anyway, hope you figure out a solution to your problem.