Sample_19_SlideMaster.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. include_once 'Sample_Header.php';
  3. use PhpOffice\PhpPresentation\PhpPresentation;
  4. use PhpOffice\PhpPresentation\Shape\Placeholder;
  5. use PhpOffice\PhpPresentation\Shape\RichText;
  6. use PhpOffice\PhpPresentation\Style\Alignment;
  7. use PhpOffice\PhpPresentation\Style\Color;
  8. use PhpOffice\PhpPresentation\Style\Fill;
  9. // Create new PHPPresentation object
  10. echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
  11. $objPHPPresentation = new PhpPresentation();
  12. // Set properties
  13. echo date('H:i:s') . ' Set properties' . EOL;
  14. $objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
  15. ->setLastModifiedBy('PHPPresentation Team')
  16. ->setTitle('Sample 19 SlideMaster')
  17. ->setSubject('Sample 19 Subject')
  18. ->setDescription('Sample 19 Description')
  19. ->setKeywords('office 2007 openxml libreoffice odt php')
  20. ->setCategory('Sample Category');
  21. // Create slide
  22. echo date('H:i:s') . ' Create slide' . EOL;
  23. $currentSlide = $objPHPPresentation->getActiveSlide();
  24. // Create a master layout
  25. echo date('H:i:s') . ' Create masterslide layout' . EOL;
  26. // Some decorative lines
  27. $oMasterSlide = $objPHPPresentation->getAllMasterSlides()[0];
  28. $shape = $oMasterSlide->createLineShape(0, 670, 960, 670)->getBorder()->setColor(new Color(Color::COLOR_RED))->setLineWidth(2);
  29. $shape = $oMasterSlide->createLineShape(0, 672, 960, 672)->getBorder()->setColor(new Color(Color::COLOR_WHITE))->setLineWidth(2);
  30. $shape = $oMasterSlide->createLineShape(0, 674, 960, 674)->getBorder()->setColor(new Color(Color::COLOR_DARKBLUE))->setLineWidth(2);
  31. // Title placeholder
  32. $shape = $oMasterSlide->createRichTextShape();
  33. $shape->setWidthAndHeight(960, 80)->setOffsetX(0)->setOffsetY(60);
  34. $shape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  35. $shape->getActiveParagraph()->getAlignment()
  36. ->setHorizontal(Alignment::HORIZONTAL_RIGHT)->setMarginLeft(200)->setMarginRight(50)
  37. ->setVertical(Alignment::VERTICAL_CENTER);
  38. $shape->getShadow()->setVisible(true)
  39. ->setDirection(90)
  40. ->setDistance(10);
  41. $shape->setAutoFit(RichText::AUTOFIT_NORMAL);
  42. $textRun = $shape->createTextRun('Titel');
  43. $textRun->getFont()->setBold(true)->setSize(30)->setColor(new Color(Color::COLOR_WHITE));
  44. $shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_TITLE));
  45. // Date placeholder
  46. $shape = $oMasterSlide->createRichTextShape();
  47. $shape->setWidthAndHeight(140, 38)->setOffsetX(50)->setOffsetY(680);
  48. $shape->getActiveParagraph()->getAlignment()
  49. ->setHorizontal(Alignment::HORIZONTAL_LEFT)
  50. ->setVertical(Alignment::VERTICAL_BASE);
  51. $shape->setAutoFit(RichText::AUTOFIT_NORMAL);
  52. $textRun = $shape->createTextRun('01-02-2000')->getFont()->setSize(18);
  53. $shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_DATETIME))->getPlaceholder()->setIdx(10);
  54. // Footer placeholder
  55. $shape = $oMasterSlide->createRichTextShape();
  56. $shape->setWidthAndHeight(468, 38)->setOffsetX(246)->setOffsetY(680);
  57. $shape->getActiveParagraph()->getAlignment()
  58. ->setHorizontal(Alignment::HORIZONTAL_CENTER)
  59. ->setVertical(Alignment::VERTICAL_BASE);
  60. $shape->setAutoFit(RichText::AUTOFIT_NORMAL);
  61. $textRun = $shape->createTextRun('Placeholder for Footer')->getFont()->setSize(18);
  62. $shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER))->getPlaceholder()->setIdx(11);
  63. // Slidenumber placeholder
  64. $shape = $oMasterSlide->createRichTextShape();
  65. $shape->setWidthAndHeight(140, 38)->setOffsetX(770)->setOffsetY(680);
  66. $shape->getActiveParagraph()->getAlignment()
  67. ->setHorizontal(Alignment::HORIZONTAL_RIGHT)
  68. ->setVertical(Alignment::VERTICAL_BASE);
  69. $shape->setAutoFit(RichText::AUTOFIT_NORMAL);
  70. $textRun = $shape->createTextRun('')->getFont()->setSize(18);
  71. $shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_SLIDENUM))->getPlaceholder()->setIdx(12);
  72. // Create a shape (drawing)
  73. echo date('H:i:s') . ' Create a shape (drawing)' . EOL;
  74. $shape = $currentSlide->createDrawingShape();
  75. $shape->setName('PHPPresentation logo')
  76. ->setDescription('PHPPresentation logo')
  77. ->setPath('./resources/phppowerpoint_logo.gif')
  78. ->setHeight(36)
  79. ->setOffsetX(10)
  80. ->setOffsetY(10);
  81. $shape->getShadow()->setVisible(true)
  82. ->setDirection(45)
  83. ->setDistance(10);
  84. $shape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
  85. // Create a shape (text) linked to a PlaceHolder
  86. echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
  87. $shape = $currentSlide->createRichTextShape();
  88. $shape->setWidthAndHeight(960, 80)->setOffsetX(0)->setOffsetY(60);
  89. $shape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
  90. $shape->getActiveParagraph()->getAlignment()
  91. ->setHorizontal(Alignment::HORIZONTAL_RIGHT)->setMarginLeft(200)->setMarginRight(50)
  92. ->setVertical(Alignment::VERTICAL_CENTER);
  93. $shape->setAutoFit(RichText::AUTOFIT_NORMAL);
  94. $shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_TITLE));
  95. echo date('H:i:s') . ' Apply the shape collection of the slide master to the slide layout' . EOL;
  96. $oSlideLayout = $oMasterSlide->getAllSlideLayouts()[0];
  97. $oSlideLayout->setShapeCollection($oMasterSlide->getShapeCollection());
  98. $currentSlide->setSlideLayout($oSlideLayout);
  99. // Save file
  100. echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
  101. if (!CLI) {
  102. include_once 'Sample_Footer.php';
  103. }