Is there a way to create Dynamic PowerPoint slides using PHP to extract content?
<p>I am trying to write a PHP script where I can hopefully extract content from a page and create PowerPoint slides with the content. I have spent most of the day messing a round with something called <a href="http://phppowerpoint.codeplex.com/" rel="nofollow">PHPPowerPoint</a> but there is no documentation, and its complicated to figure out how to use it. I have managed to make slides using PHP but it was basically hard-coding them, I would need to use variables I think. So basically I would like to run a script that takes say all text off the page and generates PowerPoint slides using my company's PP templates.</p>

<p>Does anyone have any idea how to do this, or could provide me with any advice? I would appreciate any help at all Here is the code i have so far:</p>

<pre><code>error_reporting(E_ALL);

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');

/** PHPPowerPoint */
include 'PHPPowerPoint.php';

/** PHPPowerPoint_IOFactory */
include 'PHPPowerPoint/IOFactory.php';

// Create new PHPPowerPoint object
echo date('H:i:s') . " Create new PHPPowerPoint object\n";
$objPHPPowerPoint = new PHPPowerPoint();

// Set properties
echo date('H:i:s') . " Set properties\n";
$objPHPPowerPoint-&gt;getProperties()-&gt;setCreator("Maarten Balliauw");
$objPHPPowerPoint-&gt;getProperties()-&gt;setLastModifiedBy("Maarten Balliauw");
$objPHPPowerPoint-&gt;getProperties()-&gt;setTitle("Office 2007 PPTX Test Document");
$objPHPPowerPoint-&gt;getProperties()-&gt;setSubject("Office 2007 PPTX Test Document");
$objPHPPowerPoint-&gt;getProperties()-&gt;setDescription("Test document for Office 2007 PPTX,         generated using PHP classes.");
$objPHPPowerPoint-&gt;getProperties()-&gt;setKeywords("office 2007 openxml php");
$objPHPPowerPoint-&gt;getProperties()-&gt;setCategory("Test result file");




// Remove first slide
echo date('H:i:s') . " Remove first slide\n";
$objPHPPowerPoint-&gt;removeSlideByIndex(0);

// FIRST JABIL TEMPLATE #################################
echo date('H:i:s') . " Create templated slide\n";
$currentSlide = createTemplatedSlide1($objPHPPowerPoint); // local function


// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide-&gt;createRichTextShape();
$shape-&gt;setHeight(200);
$shape-&gt;setWidth(600);
$shape-&gt;setOffsetX(10);
$shape-&gt;setOffsetY(400);
$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT     );

$textRun = $shape-&gt;createTextRun('Jabil cover slide');
$textRun-&gt;getFont()-&gt;setBold(true);
$textRun-&gt;getFont()-&gt;setSize(28);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( 'FFFFFFFF' ) );

$shape-&gt;createBreak();

$textRun = $shape-&gt;createTextRun('This was created using PHPPowerPoint');
$textRun-&gt;getFont()-&gt;setBold(true);
$textRun-&gt;getFont()-&gt;setSize(60);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( 'FFFFFFFF' ) );


// SECOND JABIL TEMPLATE #################################
echo date('H:i:s') . " Create templated slide\n";
$currentSlide = createTemplatedSlide2($objPHPPowerPoint); // local function

// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide-&gt;createRichTextShape();
$shape-&gt;setHeight(100);
$shape-&gt;setWidth(930);
$shape-&gt;setOffsetX(10);
$shape-&gt;setOffsetY(10);
$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT );

$textRun = $shape-&gt;createTextRun('Second Jabil template');
$textRun-&gt;getFont()-&gt;setBold(true);
$textRun-&gt;getFont()-&gt;setSize(48);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( 'FFFFFFFF' ) );

// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide-&gt;createRichTextShape();
$shape-&gt;setHeight(600);
$shape-&gt;setWidth(930);
$shape-&gt;setOffsetX(10);
$shape-&gt;setOffsetY(100);
$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT );

$textRun = $shape-&gt;createTextRun('- Jabil template text');
$textRun-&gt;getFont()-&gt;setSize(36);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( '#008a5e' ) );

$shape-&gt;createBreak();

$textRun = $shape-&gt;createTextRun('- Jabil template text');
$textRun-&gt;getFont()-&gt;setSize(36);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( '#005288' ) );

$shape-&gt;createBreak();

$textRun = $shape-&gt;createTextRun('- Jabil template text');
$textRun-&gt;getFont()-&gt;setSize(36);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( '#008a5e' ) );

$shape-&gt;createBreak();

$textRun = $shape-&gt;createTextRun('- Jabil template text');
$textRun-&gt;getFont()-&gt;setSize(36);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( '#005288' ) );


// THIRD JABIL TEMPLATE #################################
echo date('H:i:s') . " Create templated slide\n";
$currentSlide = createTemplatedSlide3($objPHPPowerPoint); // local function

// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide-&gt;createRichTextShape();
$shape-&gt;setHeight(100);
$shape-&gt;setWidth(930);
$shape-&gt;setOffsetX(150);
$shape-&gt;setOffsetY(10);
$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT );

$textRun = $shape-&gt;createTextRun('Third Jabil Template');
$textRun-&gt;getFont()-&gt;setBold(true);
$textRun-&gt;getFont()-&gt;setSize(48);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( '#005288' ) );

// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide-&gt;createRichTextShape();
$shape-&gt;setHeight(600);
$shape-&gt;setWidth(930);
$shape-&gt;setOffsetX(150);
$shape-&gt;setOffsetY(100);
$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT );

$textRun = $shape-&gt;createTextRun('- Jabil Template text');
$textRun-&gt;getFont()-&gt;setSize(36);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( '#008a5e' ) );

$shape-&gt;createBreak();


// FOURTH JABIL TEMPLATE #################################
echo date('H:i:s') . " Create templated slide\n";
$currentSlide = createTemplatedSlide4($objPHPPowerPoint); // local function

// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide-&gt;createRichTextShape();
$shape-&gt;setHeight(100);
$shape-&gt;setWidth(930);
$shape-&gt;setOffsetX(10);
$shape-&gt;setOffsetY(10);
$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT     );

$textRun = $shape-&gt;createTextRun('Fourth Jabil Template');
$textRun-&gt;getFont()-&gt;setBold(true);
$textRun-&gt;getFont()-&gt;setSize(48);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( 'FFFFFFFF' ) );

// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide-&gt;createRichTextShape();
$shape-&gt;setHeight(600);
$shape-&gt;setWidth(930);
$shape-&gt;setOffsetX(10);
$shape-&gt;setOffsetY(100);
$shape-&gt;getAlignment()-&gt;setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT     );

$textRun = $shape-&gt;createTextRun('Jabil template text');
$textRun-&gt;getFont()-&gt;setSize(36);
$textRun-&gt;getFont()-&gt;setColor( new PHPPowerPoint_Style_Color( '#008a5e' ) );


$fileName = 'two.pptx';
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint,     'PowerPoint2007');
$objWriter-&gt;save($fileName);



// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

// Echo done
echo date('H:i:s') . " Done writing file.\r\n";



/**
 * Creates a templated slide
 * 
 * @param PHPPowerPoint $objPHPPowerPoint
 * @return PHPPowerPoint_Slide
 */
function createTemplatedSlide1(PHPPowerPoint $objPHPPowerPoint)
{
    // Create slide
$slide = $objPHPPowerPoint-&gt;createSlide();

// Add background image
$shape = $slide-&gt;createDrawingShape();
$shape-&gt;setName('Background');
$shape-&gt;setDescription('Background');
$shape-&gt;setPath('./images/jabil.png');
$shape-&gt;setWidth(950);
$shape-&gt;setHeight(720);
$shape-&gt;setOffsetX(0);
$shape-&gt;setOffsetY(0);


// Return slide
return $slide;
}

function createTemplatedSlide2(PHPPowerPoint $objPHPPowerPoint)
{
// Create slide
$slide = $objPHPPowerPoint-&gt;createSlide();

// Add background image
$shape = $slide-&gt;createDrawingShape();
$shape-&gt;setName('Background');
$shape-&gt;setDescription('Background');
$shape-&gt;setPath('./images/jabil2.png');
$shape-&gt;setWidth(950);
$shape-&gt;setHeight(720);
$shape-&gt;setOffsetX(0);
$shape-&gt;setOffsetY(0);

// Add logo
$shape = $slide-&gt;createDrawingShape();
$shape-&gt;setName('Jabillogo');
$shape-&gt;setDescription('Jabil logo');
$shape-&gt;setPath('./images/Logo.png');
$shape-&gt;setHeight(40);
$shape-&gt;setOffsetX(10);
$shape-&gt;setOffsetY(720 - 10 - 40);

// Return slide
return $slide;
}

function createTemplatedSlide3(PHPPowerPoint $objPHPPowerPoint)
{
// Create slide
$slide = $objPHPPowerPoint-&gt;createSlide();

// Add background image
$shape = $slide-&gt;createDrawingShape();
$shape-&gt;setName('Background');
$shape-&gt;setDescription('Background');
$shape-&gt;setPath('./images/jabil3.png');
$shape-&gt;setWidth(950);
$shape-&gt;setHeight(720);
$shape-&gt;setOffsetX(0);
$shape-&gt;setOffsetY(0);



// Return slide
return $slide;
}

function createTemplatedSlide4(PHPPowerPoint $objPHPPowerPoint)
{
// Create slide
$slide = $objPHPPowerPoint-&gt;createSlide();

// Add background image
$shape = $slide-&gt;createDrawingShape();
$shape-&gt;setName('Background');
$shape-&gt;setDescription('Background');
$shape-&gt;setPath('./images/jabil4.png');
$shape-&gt;setWidth(950);
$shape-&gt;setHeight(720);
$shape-&gt;setOffsetX(0);
$shape-&gt;setOffsetY(0);



// Return slide
return $slide;
}
</code></pre>

<p>Thank you!</p>
