Sample_11_Shape.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. use PhpOffice\PhpPresentation\PhpPresentation;
  3. use PhpOffice\PhpPresentation\Style\Alignment;
  4. use PhpOffice\PhpPresentation\Style\Bullet;
  5. use PhpOffice\PhpPresentation\Style\Color;
  6. include_once 'Sample_Header.php';
  7. function fnSlideRichText(PhpPresentation $objPHPPresentation)
  8. {
  9. // Create templated slide
  10. echo date('H:i:s') . ' Create templated slide' . EOL;
  11. $currentSlide = createTemplatedSlide($objPHPPresentation);
  12. // Create a shape (text)
  13. echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
  14. $shape = $currentSlide->createRichTextShape();
  15. $shape->setHeight(100);
  16. $shape->setWidth(600);
  17. $shape->setOffsetX(100);
  18. $shape->setOffsetY(100);
  19. $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
  20. $textRun = $shape->createTextRun('RichText with');
  21. $textRun->getFont()->setBold(true);
  22. $textRun->getFont()->setSize(28);
  23. $textRun->getFont()->setColor(new Color('FF000000'));
  24. $shape->createBreak();
  25. $textRun = $shape->createTextRun('Multiline');
  26. $textRun->getFont()->setBold(true);
  27. $textRun->getFont()->setSize(60);
  28. $textRun->getFont()->setColor(new Color('FF000000'));
  29. }
  30. function fnSlideRichTextLineSpacing(PhpPresentation $objPHPPresentation)
  31. {
  32. // Create templated slide
  33. echo date('H:i:s') . ' Create templated slide' . EOL;
  34. $currentSlide = createTemplatedSlide($objPHPPresentation);
  35. // Create a shape (text)
  36. echo date('H:i:s') . ' Create a shape (rich text) with line spacing (100)' . EOL;
  37. $shape = $currentSlide->createRichTextShape();
  38. $shape->setHeight(100);
  39. $shape->setWidth(400);
  40. $shape->setOffsetX(100);
  41. $shape->setOffsetY(100);
  42. $shape->getActiveParagraph()->setLineSpacing(100);
  43. $shape->createTextRun('RichText with');
  44. $shape->createBreak();
  45. $shape->createTextRun('Line Spacing 100');
  46. // Create a shape (text)
  47. echo date('H:i:s') . ' Create a shape (rich text) with line spacing (200)' . EOL;
  48. $shape = $currentSlide->createRichTextShape();
  49. $shape->setHeight(100);
  50. $shape->setWidth(400);
  51. $shape->setOffsetX(100);
  52. $shape->setOffsetY(200);
  53. $shape->getActiveParagraph()->setLineSpacing(200);
  54. $shape->createTextRun('RichText with');
  55. $shape->createBreak();
  56. $shape->createTextRun('Line Spacing 200');
  57. // Create a shape (text)
  58. echo date('H:i:s') . ' Create a shape (rich text) with line spacing (300)' . EOL;
  59. $shape = $currentSlide->createRichTextShape();
  60. $shape->setHeight(100);
  61. $shape->setWidth(400);
  62. $shape->setOffsetX(100);
  63. $shape->setOffsetY(300);
  64. $shape->getActiveParagraph()->setLineSpacing(300);
  65. $shape->createTextRun('RichText with');
  66. $shape->createBreak();
  67. $shape->createTextRun('Line Spacing 300');
  68. }
  69. function fnSlideRichTextShadow(PhpPresentation $objPHPPresentation)
  70. {
  71. // Create templated slide
  72. echo date('H:i:s') . ' Create templated slide' . EOL;
  73. $currentSlide = createTemplatedSlide($objPHPPresentation);
  74. // Create a shape (text)
  75. echo date('H:i:s') . ' Create a shape (rich text) with shadow' . EOL;
  76. $shape = $currentSlide->createRichTextShape();
  77. $shape->setHeight(100);
  78. $shape->setWidth(400);
  79. $shape->setOffsetX(100);
  80. $shape->setOffsetY(100);
  81. $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
  82. $shape->getShadow()->setVisible(true)->setAlpha(75)->setBlurRadius(2)->setDirection(45);
  83. $textRun = $shape->createTextRun('RichText with shadow');
  84. $textRun->getFont()->setColor(new Color('FF000000'));
  85. }
  86. function fnSlideRichTextList(PhpPresentation $objPHPPresentation)
  87. {
  88. // Create templated slide
  89. echo date('H:i:s') . ' Create templated slide' . EOL;
  90. $currentSlide = createTemplatedSlide($objPHPPresentation);
  91. // Create a shape (text)
  92. echo date('H:i:s') . ' Create a shape (rich text) with list with red bullet' . EOL;
  93. $shape = $currentSlide->createRichTextShape();
  94. $shape->setHeight(100);
  95. $shape->setWidth(400);
  96. $shape->setOffsetX(100);
  97. $shape->setOffsetY(100);
  98. $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET)->setBulletColor(new Color(Color::COLOR_RED));
  99. $shape->createTextRun('Alpha');
  100. $shape->createParagraph()->createTextRun('Beta');
  101. $shape->createParagraph()->createTextRun('Delta');
  102. $shape->createParagraph()->createTextRun('Epsilon');
  103. }
  104. // Create new PHPPresentation object
  105. echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
  106. $objPHPPresentation = new PhpPresentation();
  107. // Set properties
  108. echo date('H:i:s') . ' Set properties' . EOL;
  109. $oProperties = $objPHPPresentation->getDocumentProperties();
  110. $oProperties->setCreator('PHPOffice')
  111. ->setLastModifiedBy('PHPPresentation Team')
  112. ->setTitle('Sample 11 Title')
  113. ->setSubject('Sample 11 Subject')
  114. ->setDescription('Sample 11 Description')
  115. ->setKeywords('office 2007 openxml libreoffice odt php')
  116. ->setCategory('Sample Category');
  117. // Remove first slide
  118. echo date('H:i:s') . ' Remove first slide' . EOL;
  119. $objPHPPresentation->removeSlideByIndex(0);
  120. fnSlideRichText($objPHPPresentation);
  121. fnSlideRichTextLineSpacing($objPHPPresentation);
  122. fnSlideRichTextShadow($objPHPPresentation);
  123. fnSlideRichTextList($objPHPPresentation);
  124. // Save file
  125. echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
  126. if (!CLI) {
  127. include_once 'Sample_Footer.php';
  128. }