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