Skip to content

Commit 2724dc2

Browse files
committed
Added Sample for the PowerPoint97 Reader - @Progi1984 GH-110
1 parent a89c1fb commit 2724dc2

File tree

5 files changed

+267
-1
lines changed

5 files changed

+267
-1
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
3+
set_time_limit(10);
4+
5+
include_once 'Sample_Header.php';
6+
7+
use PhpOffice\PhpPowerpoint\PhpPowerpoint;
8+
use PhpOffice\PhpPowerpoint\DocumentLayout;
9+
use PhpOffice\PhpPowerpoint\IOFactory;
10+
use PhpOffice\PhpPowerpoint\Style\Alignment;
11+
use PhpOffice\PhpPowerpoint\Style\Color;
12+
use PhpOffice\PhpPowerpoint\Slide;
13+
use PhpOffice\PhpPowerpoint\AbstractShape;
14+
use PhpOffice\PhpPowerpoint\Shape\MemoryDrawing;
15+
use PhpOffice\PhpPowerpoint\Shape\RichText;
16+
use PhpOffice\PhpPowerPoint\Shape\Group;
17+
18+
class PhpPptTree {
19+
protected $oPhpPowerpoint;
20+
protected $htmlOutput;
21+
22+
public function __construct(PhpPowerpoint $oPHPPpt)
23+
{
24+
$this->oPhpPowerpoint = $oPHPPpt;
25+
}
26+
27+
public function display()
28+
{
29+
$this->append('<div class="container-fluid pptTree">');
30+
$this->append('<div class="row">');
31+
$this->append('<div class="collapse in col-md-6">');
32+
$this->append('<div class="tree">');
33+
$this->append('<ul>');
34+
$this->displayPhpPowerpoint($this->oPhpPowerpoint);
35+
$this->append('</ul>');
36+
$this->append('</div>');
37+
$this->append('</div>');
38+
$this->append('<div class="col-md-6">');
39+
$this->displayPhpPowerpointInfo($this->oPhpPowerpoint);
40+
$this->append('</div>');
41+
$this->append('</div>');
42+
$this->append('</div>');
43+
44+
return $this->htmlOutput;
45+
}
46+
47+
protected function append($sHTML)
48+
{
49+
$this->htmlOutput .= $sHTML;
50+
}
51+
52+
protected function displayPhpPowerpoint(PhpPowerpoint $oPHPPpt)
53+
{
54+
$this->append('<li><span><i class="fa fa-folder-open"></i> PhpPowerpoint</span>');
55+
$this->append('<ul>');
56+
$this->append('<li><span class="shape" id="divPhpPowerpoint"><i class="fa fa-info-circle"></i> Info "PhpPowerpoint"</span></li>');
57+
foreach ($oPHPPpt->getAllSlides() as $oSlide) {
58+
$this->append('<li><span><i class="fa fa-minus-square"></i> Slide</span>');
59+
$this->append('<ul>');
60+
$this->append('<li><span class="shape" id="div'.$oSlide->getHashCode().'"><i class="fa fa-info-circle"></i> Info "Slide"</span></li>');
61+
foreach ($oSlide->getShapeCollection() as $oShape) {
62+
if($oShape instanceof Group) {
63+
$this->append('<li><span><i class="fa fa-minus-square"></i> Shape "Group"</span>');
64+
$this->append('<ul>');
65+
// $this->append('<li><span class="shape" id="div'.$oShape->getHashCode().'"><i class="fa fa-info-circle"></i> Info "Group"</span></li>');
66+
foreach ($oShape->getShapeCollection() as $oShapeChild) {
67+
$this->displayShape($oShapeChild);
68+
}
69+
$this->append('</ul>');
70+
$this->append('</li>');
71+
} else {
72+
$this->displayShape($oShape);
73+
}
74+
}
75+
$this->append('</ul>');
76+
$this->append('</li>');
77+
}
78+
$this->append('</ul>');
79+
$this->append('</li>');
80+
}
81+
82+
protected function displayShape(AbstractShape $shape)
83+
{
84+
if($shape instanceof MemoryDrawing) {
85+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "MemoryDrawing"</span></li>');
86+
} elseif($shape instanceof RichText) {
87+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "RichText"</span></li>');
88+
} else {
89+
var_export($shape);
90+
}
91+
}
92+
93+
protected function displayPhpPowerpointInfo(PhpPowerpoint $oPHPPpt)
94+
{
95+
$this->append('<div class="infoBlk" id="divPhpPowerpointInfo">');
96+
$this->append('<dl>');
97+
$this->append('<dt>Number of slides</dt><dd>'.$oPHPPpt->getSlideCount().'</dd>');
98+
$this->append('<dt>Document Layout Height</dt><dd>'.$oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER).' mm</dd>');
99+
$this->append('<dt>Document Layout Width</dt><dd>'.$oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER).' mm</dd>');
100+
$this->append('<dt>Properties : Category</dt><dd>'.$oPHPPpt->getProperties()->getCategory().'</dd>');
101+
$this->append('<dt>Properties : Company</dt><dd>'.$oPHPPpt->getProperties()->getCompany().'</dd>');
102+
$this->append('<dt>Properties : Created</dt><dd>'.$oPHPPpt->getProperties()->getCreated().'</dd>');
103+
$this->append('<dt>Properties : Creator</dt><dd>'.$oPHPPpt->getProperties()->getCreator().'</dd>');
104+
$this->append('<dt>Properties : Description</dt><dd>'.$oPHPPpt->getProperties()->getDescription().'</dd>');
105+
$this->append('<dt>Properties : Keywords</dt><dd>'.$oPHPPpt->getProperties()->getKeywords().'</dd>');
106+
$this->append('<dt>Properties : Last Modified By</dt><dd>'.$oPHPPpt->getProperties()->getLastModifiedBy().'</dd>');
107+
$this->append('<dt>Properties : Modified</dt><dd>'.$oPHPPpt->getProperties()->getModified().'</dd>');
108+
$this->append('<dt>Properties : Subject</dt><dd>'.$oPHPPpt->getProperties()->getSubject().'</dd>');
109+
$this->append('<dt>Properties : Title</dt><dd>'.$oPHPPpt->getProperties()->getTitle().'</dd>');
110+
$this->append('</dl>');
111+
$this->append('</div>');
112+
113+
foreach ($oPHPPpt->getAllSlides() as $oSlide) {
114+
$this->append('<div class="infoBlk" id="div'.$oSlide->getHashCode().'Info">');
115+
$this->append('<dl>');
116+
$this->append('<dt>HashCode</dt><dd>'.$oSlide->getHashCode().'</dd>');
117+
$this->append('<dt>Slide Layout</dt><dd>'.$oSlide->getSlideLayout().'</dd>');
118+
$this->append('<dt>Offset X</dt><dd>'.$oSlide->getOffsetX().'</dd>');
119+
$this->append('<dt>Offset Y</dt><dd>'.$oSlide->getOffsetY().'</dd>');
120+
$this->append('<dt>Extent X</dt><dd>'.$oSlide->getExtentX().'</dd>');
121+
$this->append('<dt>Extent Y</dt><dd>'.$oSlide->getExtentY().'</dd>');
122+
$this->append('</dl>');
123+
$this->append('</div>');
124+
125+
foreach ($oSlide->getShapeCollection() as $oShape) {
126+
if($oShape instanceof Group) {
127+
foreach ($oShape->getShapeCollection() as $oShapeChild) {
128+
$this->displayShapeInfo($oShapeChild);
129+
}
130+
} else {
131+
$this->displayShapeInfo($oShape);
132+
}
133+
}
134+
}
135+
}
136+
137+
protected function displayShapeInfo(AbstractShape $oShape)
138+
{
139+
$this->append('<div class="infoBlk" id="div'.$oShape->getHashCode().'Info">');
140+
$this->append('<dl>');
141+
$this->append('<dt>HashCode</dt><dd>'.$oShape->getHashCode().'</dd>');
142+
$this->append('<dt>Offset X</dt><dd>'.$oShape->getOffsetX().'</dd>');
143+
$this->append('<dt>Offset Y</dt><dd>'.$oShape->getOffsetY().'</dd>');
144+
$this->append('<dt>Height</dt><dd>'.$oShape->getHeight().'</dd>');
145+
$this->append('<dt>Width</dt><dd>'.$oShape->getWidth().'</dd>');
146+
$this->append('<dt>Rotation</dt><dd>'.$oShape->getRotation().'°</dd>');
147+
$this->append('<dt>Hyperlink</dt><dd>'.ucfirst(var_export($oShape->hasHyperlink(), true)).'</dd>');
148+
$this->append('<dt>Fill</dt><dd>@Todo</dd>');
149+
$this->append('<dt>Border</dt><dd>@Todo</dd>');
150+
if($oShape instanceof MemoryDrawing) {
151+
ob_start();
152+
call_user_func($oShape->getRenderingFunction(), $oShape->getImageResource());
153+
$sShapeImgContents = ob_get_contents();
154+
ob_end_clean();
155+
$this->append('<dt>Mime-Type</dt><dd>'.$oShape->getMimeType().'</dd>');
156+
$this->append('<dt>Image</dt><dd><img src="data:'.$oShape->getMimeType().';base64,'.base64_encode($sShapeImgContents).'"></dd>');
157+
} else {
158+
// Add another shape
159+
}
160+
$this->append('</dl>');
161+
$this->append('</div>');
162+
}
163+
}
164+
165+
$pptReader = PhpOffice\PhpPowerpoint\IOFactory::createReader('PowerPoint97');
166+
$oPHPPowerPoint = $pptReader->load('resources/Sample_12.ppt');
167+
168+
$oTree = new PhpPptTree($oPHPPowerPoint);
169+
echo $oTree->display();
170+
if (!CLI) {
171+
include_once 'Sample_Footer.php';
172+
}

samples/Sample_Footer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
</div>
77
<script src="bootstrap/js/jquery.min.js"></script>
88
<script src="bootstrap/js/bootstrap.min.js"></script>
9+
<script src="bootstrap/js/script.js"></script>
910
</body>
1011
</html>

samples/bootstrap/css/phppowerpoint.css

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
body {
22
padding-top: 20px;
33
padding-bottom: 20px;
4-
min-height: 1000px;
54
}
65
.navbar {
76
margin-bottom: 20px;
@@ -12,3 +11,77 @@ body {
1211
.failed {
1312
color: #ff0000;
1413
}
14+
.tree {
15+
min-height:20px;
16+
padding:19px;
17+
margin-bottom:20px;
18+
background-color:#fbfbfb;
19+
-webkit-border-radius:4px;
20+
-moz-border-radius:4px;
21+
}
22+
.tree li {
23+
list-style-type:none;
24+
margin:0;
25+
padding:10px 5px 0 5px;
26+
position:relative
27+
}
28+
.tree li::before, .tree li::after {
29+
content:'';
30+
left:-20px;
31+
position:absolute;
32+
right:auto
33+
}
34+
.tree li::before {
35+
border-left:1px solid #999;
36+
bottom:50px;
37+
height:100%;
38+
top:0;
39+
width:1px
40+
}
41+
.tree li::after {
42+
border-top:1px solid #999;
43+
height:20px;
44+
top:30px;
45+
width:25px
46+
}
47+
.tree li span {
48+
-moz-border-radius:5px;
49+
-webkit-border-radius:5px;
50+
border:1px solid #999;
51+
border-radius:5px;
52+
display:inline-block;
53+
padding:3px 8px;
54+
text-decoration:none
55+
}
56+
.tree li.parent_li>span {
57+
cursor:pointer
58+
}
59+
.tree>ul>li::before, .tree>ul>li::after {
60+
border:0
61+
}
62+
.tree li:last-child::before {
63+
height:30px
64+
}
65+
.tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span {
66+
background:#eee;
67+
border:1px solid #94a0b4;
68+
color:#000
69+
}
70+
71+
.tree .shape {
72+
cursor: pointer;
73+
}
74+
75+
.infoBlk {
76+
display:none;
77+
}
78+
79+
.pptTree {
80+
background-color:#fbfbfb;
81+
}
82+
.pptTree dd {
83+
margin-left: 20px;
84+
}
85+
86+
.pptTree dd img {
87+
max-width: 50%;

samples/bootstrap/js/script.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$(function () {
2+
$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
3+
$('.tree li.parent_li > span').on('click', function (e) {
4+
var children = $(this).parent('li.parent_li').find(' > ul > li');
5+
if (children.is(":visible")) {
6+
children.hide('fast');
7+
$(this).attr('title', 'Expand this branch').find(' > i').addClass('fa-plus-square').removeClass('fa-minus-square');
8+
} else {
9+
children.show('fast');
10+
$(this).attr('title', 'Collapse this branch').find(' > i').addClass('fa-minus-square').removeClass('fa-plus-square');
11+
}
12+
e.stopPropagation();
13+
});
14+
15+
$('.tree .shape').on('click', function (e) {
16+
$('.infoBlk').hide();
17+
$('.infoBlk#' + $(this).attr('id') + 'Info').show();
18+
e.stopPropagation();
19+
});
20+
});

samples/resources/Sample_12.ppt

86.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)