Sample_01_Complex.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. $colorBlack = new Color( 'FF000000' );
  8. // Create new PHPPresentation object
  9. echo date('H:i:s') . ' Create new PHPPresentation object'.EOL;
  10. $objPHPPresentation = new PhpPresentation();
  11. // Set properties
  12. echo date('H:i:s') . ' Set properties'.EOL;
  13. $objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
  14. ->setLastModifiedBy('PHPPresentation Team')
  15. ->setTitle('Sample 02 Title')
  16. ->setSubject('Sample 02 Subject')
  17. ->setDescription('Sample 02 Description')
  18. ->setKeywords('office 2007 openxml libreoffice odt php')
  19. ->setCategory('Sample Category');
  20. // Remove first slide
  21. echo date('H:i:s') . ' Remove first slide'.EOL;
  22. $objPHPPresentation->removeSlideByIndex(0);
  23. // Create templated slide
  24. echo date('H:i:s') . ' Create templated slide'.EOL;
  25. $currentSlide = createTemplatedSlide($objPHPPresentation); // local function
  26. // Create a shape (text)
  27. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  28. $shape = $currentSlide->createRichTextShape();
  29. $shape->setHeight(200);
  30. $shape->setWidth(600);
  31. $shape->setOffsetX(10);
  32. $shape->setOffsetY(400);
  33. $shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_LEFT );
  34. $textRun = $shape->createTextRun('Introduction to');
  35. $textRun->getFont()->setBold(true);
  36. $textRun->getFont()->setSize(28);
  37. $textRun->getFont()->setColor($colorBlack);
  38. $shape->createBreak();
  39. $textRun = $shape->createTextRun('PHPPresentation');
  40. $textRun->getFont()->setBold(true);
  41. $textRun->getFont()->setSize(60);
  42. $textRun->getFont()->setColor($colorBlack);
  43. // Create templated slide
  44. echo date('H:i:s') . ' Create templated slide'.EOL;
  45. $currentSlide = createTemplatedSlide($objPHPPresentation); // local function
  46. // Create a shape (text)
  47. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  48. $shape = $currentSlide->createRichTextShape();
  49. $shape->setHeight(100)
  50. ->setWidth(930)
  51. ->setOffsetX(10)
  52. ->setOffsetY(50);
  53. $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
  54. $textRun = $shape->createTextRun('What is PHPPresentation?');
  55. $textRun->getFont()->setBold(true)
  56. ->setSize(48)
  57. ->setColor($colorBlack);
  58. // Create a shape (text)
  59. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  60. $shape = $currentSlide->createRichTextShape()
  61. ->setHeight(600)
  62. ->setWidth(930)
  63. ->setOffsetX(10)
  64. ->setOffsetY(130);
  65. $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)
  66. ->setMarginLeft(25)
  67. ->setIndent(-25);
  68. $shape->getActiveParagraph()->getFont()->setSize(36)
  69. ->setColor($colorBlack);
  70. $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
  71. $shape->createTextRun('A class library');
  72. $shape->createParagraph()->createTextRun('Written in PHP');
  73. $shape->createParagraph()->createTextRun('Representing a presentation');
  74. $shape->createParagraph()->createTextRun('Supports writing to different file formats');
  75. // Create templated slide
  76. echo date('H:i:s') . ' Create templated slide'.EOL;
  77. $currentSlide = createTemplatedSlide($objPHPPresentation); // local function
  78. // Create a shape (text)
  79. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  80. $shape = $currentSlide->createRichTextShape()
  81. ->setHeight(100)
  82. ->setWidth(930)
  83. ->setOffsetX(10)
  84. ->setOffsetY(50);
  85. $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT );
  86. $textRun = $shape->createTextRun('What\'s the point?');
  87. $textRun->getFont()->setBold(true)
  88. ->setSize(48)
  89. ->setColor($colorBlack);
  90. // Create a shape (text)
  91. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  92. $shape = $currentSlide->createRichTextShape();
  93. $shape->setHeight(600)
  94. ->setWidth(930)
  95. ->setOffsetX(10)
  96. ->setOffsetY(130);
  97. $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)
  98. ->setMarginLeft(25)
  99. ->setIndent(-25);
  100. $shape->getActiveParagraph()->getFont()->setSize(36)
  101. ->setColor($colorBlack);
  102. $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
  103. $shape->createTextRun('Generate slide decks');
  104. $shape->createParagraph()->getAlignment()->setLevel(1)
  105. ->setMarginLeft(75)
  106. ->setIndent(-25);
  107. $shape->createTextRun('Represent business data');
  108. $shape->createParagraph()->createTextRun('Show a family slide show');
  109. $shape->createParagraph()->createTextRun('...');
  110. $shape->createParagraph()->getAlignment()->setLevel(0)
  111. ->setMarginLeft(25)
  112. ->setIndent(-25);
  113. $shape->createTextRun('Export these to different formats');
  114. $shape->createParagraph()->getAlignment()->setLevel(1)
  115. ->setMarginLeft(75)
  116. ->setIndent(-25);
  117. $shape->createTextRun('PHPPresentation 2007');
  118. $shape->createParagraph()->createTextRun('Serialized');
  119. $shape->createParagraph()->createTextRun('... (more to come) ...');
  120. // Create templated slide
  121. echo date('H:i:s') . ' Create templated slide'.EOL;
  122. $currentSlide = createTemplatedSlide($objPHPPresentation); // local function
  123. // Create a shape (text)
  124. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  125. $shape = $currentSlide->createRichTextShape();
  126. $shape->setHeight(100)
  127. ->setWidth(930)
  128. ->setOffsetX(10)
  129. ->setOffsetY(50);
  130. $shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_LEFT );
  131. $textRun = $shape->createTextRun('Need more info?');
  132. $textRun->getFont()->setBold(true)
  133. ->setSize(48)
  134. ->setColor($colorBlack);
  135. // Create a shape (text)
  136. echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
  137. $shape = $currentSlide->createRichTextShape();
  138. $shape->setHeight(600)
  139. ->setWidth(930)
  140. ->setOffsetX(10)
  141. ->setOffsetY(130);
  142. $shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_LEFT );
  143. $textRun = $shape->createTextRun('Check the project site on GitHub:');
  144. $textRun->getFont()->setSize(36)
  145. ->setColor($colorBlack);
  146. $shape->createBreak();
  147. $textRun = $shape->createTextRun('https://github.com/PHPOffice/PHPPresentation/');
  148. $textRun->getFont()->setSize(32)
  149. ->setColor($colorBlack);
  150. $textRun->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')
  151. ->setTooltip('PHPPresentation');
  152. // Save file
  153. echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
  154. if (!CLI) {
  155. include_once 'Sample_Footer.php';
  156. }