Sample_06_Fill.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. include_once 'Sample_Header.php';
  3. use PhpOffice\PhpPresentation\PhpPresentation;
  4. use PhpOffice\PhpPresentation\Style\Alignment;
  5. use PhpOffice\PhpPresentation\Style\Color;
  6. use PhpOffice\PhpPresentation\Style\Fill;
  7. // Create new PHPPresentation object
  8. echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
  9. $objPHPPresentation = new PhpPresentation();
  10. // Set properties
  11. echo date('H:i:s') . ' Set properties'.EOL;
  12. $objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
  13. ->setLastModifiedBy('PHPPresentation Team')
  14. ->setTitle('Sample 01 Title')
  15. ->setSubject('Sample 01 Subject')
  16. ->setDescription('Sample 01 Description')
  17. ->setKeywords('office 2007 openxml libreoffice odt php')
  18. ->setCategory('Sample Category');
  19. // Create slide
  20. echo date('H:i:s') . ' Create slide'.EOL;
  21. $currentSlide = $objPHPPresentation->getActiveSlide();
  22. for($inc = 1 ; $inc <= 4 ; $inc++){
  23. // Create a shape (text)
  24. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  25. $shape = $currentSlide->createRichTextShape()
  26. ->setHeight(200)
  27. ->setWidth(300);
  28. if($inc == 1 || $inc == 3){
  29. $shape->setOffsetX(10);
  30. } else {
  31. $shape->setOffsetX(320);
  32. }
  33. if($inc == 1 || $inc == 2){
  34. $shape->setOffsetY(10);
  35. } else {
  36. $shape->setOffsetY(220);
  37. }
  38. $shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
  39. switch ($inc) {
  40. case 1 :
  41. $shape->getFill()->setFillType(Fill::FILL_NONE);
  42. break;
  43. case 2 :
  44. $shape->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)->setRotation(90)->setStartColor(new Color( 'FF4672A8' ))->setEndColor(new Color( 'FF000000' ));
  45. break;
  46. case 3 :
  47. $shape->getFill()->setFillType(Fill::FILL_GRADIENT_PATH)->setRotation(90)->setStartColor(new Color( 'FF4672A8' ))->setEndColor(new Color( 'FF000000' ));
  48. break;
  49. case 4 :
  50. $shape->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color( 'FF4672A8' ))->setEndColor(new Color( 'FF4672A8' ));
  51. break;
  52. }
  53. $textRun = $shape->createTextRun('Use PHPPresentation!');
  54. $textRun->getFont()->setBold(true)
  55. ->setSize(30)
  56. ->setColor( new Color('FFE06B20') );
  57. }
  58. // Save file
  59. echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
  60. if (!CLI) {
  61. include_once 'Sample_Footer.php';
  62. }