Location: PHPKode > projects > ClPHPppt > clphpppt/samples/sample1.php
<?php
  //You need clPHPppt.php
  require_once("../src/clPHPppt.php");
  
  //Define the to store location
  $scriptPath = $_SERVER['SCRIPT_FILENAME'];
  $basePath = substr($scriptPath, 0, strrpos($scriptPath, "\\"))."\\";
  $saveFilename = $basePath."out.ppt";
  $templateFilename = $basePath."sample.pot";
  
  //Initialize the Class including the setting for visibility of PowerPoint
  $ppt = new clPHPppt(true, $templateFilename);
  
  //Class with the constants constants
  $ppConstants = new ppConstants();
  
  //Read out the PowerPoint Version
  echo "clPHPppt has access to Microsoft PowerPoint v".$ppt->pptVersion().'<br />';
  
  //Add some Slides
  $ppt->addSlide(1, $ppConstants->ppSlideLayouts->ppLayoutTitle);
  $ppt->addSlide(2, $ppConstants->ppSlideLayouts->ppLayoutText);
  $ppt->addSlide(3, $ppConstants->ppSlideLayouts->ppLayoutTitleOnly);
  
  //Fill the basic layout
  $ppt->setShapeText(1,1,"Welcome to clPHPppt");
  $ppt->setShapeText(1,2,"The Microsoft® PowerPoint® PHP Class");
  
  $ppt->setShapeText(2,1,"What can clPHPppt do?");
  $ppt->setShapeText(2,2,"It can\r\nOpen existing PowerPoint files and templates\r\n".
	"create a new presentation\r\nadd and delete\r\npictures\r\ntext boxes\r\n".
	"AutoShapes\r\nWordArt\r\ntables and\r\nOLE objects\r\nmodify miscellaneous ".
	"setting including text, color and shadows");
  //No Level for the first Object (doesn't work right now)
  $ppt->setIndent(2, 2, 1, 1, 0, 1); 
  //"add and delete" sub items should be on the second level
  $ppt->setIndent(2, 2, 5, 6, 2, 1); 
  
  
  $ppt->setShapeText(3,1,"Miscellaneous elements added dynamically");
  
  
  //Add a picture
  $ppt->addPicture(3, $basePath."sample.png", 50,150);
  
  //Add a Textbox with special font settings
  $settings = array (
	'fontName' => 'Verdana',
	'fontSize' => 24,
	'fontBold' => false,
	'fontItalic' => false,
	'fontShadow' => true,
	'fontUnderline' => true,
	'fontColor' => $ppt->getVBColorFromRGB(15,45,128),
	'textAlign' => $ppConstants->ppTextAligns->ppTextAlignCenter,
	'rotation' => 15,
	'fillEnabled' => true,
	'fillForeColor' => $ppt->getVBColorFromRGB(128,45,15),
	'fillTransparency' => 0.8
  );  
  $ppt->addTextbox(3, "Test TexBox", 275, 175, 300, 40, $settings);
  
  //Add a Autoshape with special settings
  $settings = array(
	'fillEnabled' => true,
	'fillForeColor' => $ppt->getVBColorFromHEX('#E2007A'),
	'fillTransparency' => 0.5,
	'lineEnabled' => true,
	'lineWeight' => 5,
	'lineDashStyle' => $ppConstants->ppLineDashStyles->msoLineDashDotDot,
	'lineForeColor' => $ppt->getVBColorFromHEX('#576865'),
	'lineTransparency' => 0.2
  );
  $ppt->addShape(3, $ppConstants->ppAutoShapeTypes->msoShapeCloudCallout, 325, 150, 200,100, $settings);
  
  $ppt->addTextbox(3, "We can also get the text from a shape - ".
	"of course unformatted:\r\n".$ppt->getShapeText(3,1), 355, 300, 350, 100);
  
  //Add some Lines and Arrows
  $ppt->addLine(3, 100, 400, 450, 450);
  
  $settings = array(
	'lineWeight' => 1.5,
	'lineBeginArrowStyle' => $ppConstants->ppArrowStyles->msoArrowheadTriangle,
	'lineBeginArrowWidth' => $ppConstants->ppArrowWidths->msoArrowheadWide,
	'lineBeginArrowLength' => $ppConstants->ppArrowLengths->msoArrowheadLong
  );
  $ppt->addLine(3, 220, 425, 150, 450, $settings);
  
  //WordArt!
  $wordart = $ppt->addTextEffect(3, $ppConstants->ppTextEffectStyles->msoTextEffect28, 475, 375, 
	"WordArt!", "Verdana", 36, true, false);
  $settings = array(
	'fillColor' => $ppt->getVBColorFromHEX('#E20074'),
	'shadowType' => $ppConstants->ppShadowTypes->msoShadow19,
	'shadowForeColor' => $ppt->getVBColorFromHEX('#E20074'),
	'shadowTransparency' => 0.5
  );
  $ppt->applySettings(-1, $wordart, $settings);
  
  $ppt->deleteShape(-1, $wordart);
  
  //Add an OLE Object to the slide with an icon and no link
  $excelFile = $basePath."sample.xls";
  $ppt->addOLEObject(3, 375, 375, 64, 64, $excelFile, true);
  
  
  //Work with Tables
  $ppt->addSlide(4, $ppConstants->ppSlideLayouts->ppLayoutTitleOnly);
  $ppt->setShapeText(4, 1, "Would you like to have a table?");
  $table = $ppt->addTable(4, 2, 2, 50, 150, 620, 340);
  
  $settings = array(
	'lineEnabled' => true,
	'lineWeight' => 1
  );
  $ppt->applySettings(-1, $table, $settings);
  
  $settings = array(
	'fillEnabled' => true,
	'fillForeColor' => $ppt->getVBColorFromHEX('#E2007A'),
	'color' => $ppt->getVBColorFromHEX('#181186')
  );
  $ppt->setTableText(4, 2, 1, 1, "You're welcome!", $settings);
  $ppt->setTableText(4, 2, 1, 2, "Every cell can be accessed and manipulated with the known settings!", $settings);
  $ppt->setTableText(4, 2, 2, 1, "And of course you can split and join cells!");
  
  $ppt->mergeTableCells(4, 2, 2,1, 2,2);

  
  $ppt->save($saveFilename);
  $ppt = null;
  
  echo '<a href="out.ppt">download</a>';
?>
Return current item: ClPHPppt