Skip to content

Commit 92ffaf4

Browse files
committed
PowerPoint2007 Writer : Keynote incompatibility (CodePlex#237322)
1 parent 321bf4f commit 92ffaf4

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Bugfix
1111
- PowerPoint2007 Writer : Powerpoint Repair Error in Office 2010 - @Progi1984 GH-39
1212
- PowerPoint2007 Writer : BUG: Repair Error / Wrong anchor if you don't set vertical alignment different to VERTICAL_BASE - @fregge GH-42
13+
- PowerPoint2007 Writer : Keynote incompatibility - @catrane CP#237322
1314

1415
### Miscellaneous
1516
- QA : Move AbstractType for Chart - @Progi1984

src/PhpPowerpoint/Writer/PowerPoint2007.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\DocProps;
2929
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Drawing;
3030
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\LayoutPack\PackDefault;
31+
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\PptProps;
3132
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Presentation;
3233
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Rels;
3334
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Slide;
@@ -105,6 +106,7 @@ public function __construct(PHPPowerPoint $pPHPPowerPoint = null)
105106

106107
// Initialise writer parts
107108
$this->writerParts['contenttypes'] = new ContentTypes();
109+
$this->writerParts['pptprops'] = new PptProps();
108110
$this->writerParts['docprops'] = new DocProps();
109111
$this->writerParts['rels'] = new Rels();
110112
$this->writerParts['theme'] = new Theme();
@@ -190,6 +192,10 @@ public function save($pFilename)
190192
if (!$wPartChart instanceof Chart) {
191193
throw new \Exception('The $parentWriter is not an instance of \PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Chart');
192194
}
195+
$wPptProps = $this->getWriterPart('PptProps');
196+
if (!$wPptProps instanceof PptProps) {
197+
throw new \Exception('The $parentWriter is not an instance of \PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\PptProps');
198+
}
193199

194200
// Create drawing dictionary
195201
$this->drawingHashTable->addFromSource($wPartDrawing->allDrawings($this->presentation));
@@ -207,9 +213,14 @@ public function save($pFilename)
207213
// Add [Content_Types].xml to ZIP file
208214
$objZip->addFromString('[Content_Types].xml', $wPartContentTypes->writeContentTypes($this->presentation));
209215

216+
// Add PPT properties and styles to ZIP file - Required for Apple Keynote compatibility.
217+
$objZip->addFromString('ppt/presProps.xml', $wPptProps->writePresProps($this->presentation));
218+
$objZip->addFromString('ppt/tableStyles.xml', $wPptProps->writeTableStyles($this->presentation));
219+
210220
// Add relationships to ZIP file
211221
$objZip->addFromString('_rels/.rels', $wPartRels->writeRelationships());
212222
$objZip->addFromString('ppt/_rels/presentation.xml.rels', $wPartRels->writePresentationRelationships($this->presentation));
223+
213224
// Add document properties to ZIP file
214225
$objZip->addFromString('docProps/app.xml', $wPartDocProps->writeDocPropsApp($this->presentation));
215226
$objZip->addFromString('docProps/core.xml', $wPartDocProps->writeDocPropsCore($this->presentation));
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPowerPoint - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPowerPoint is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPPowerPoint
14+
* @copyright 2009-2014 PHPPowerPoint contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpPowerpoint\Writer\PowerPoint2007;
19+
20+
use PhpOffice\PhpPowerpoint\PhpPowerpoint;
21+
22+
class PptProps extends AbstractPart
23+
{
24+
/**
25+
* Write ppt/presProps.xml to XML format
26+
*
27+
* @param PhpPowerpoint $pPHPPowerPoint
28+
* @return string XML Output
29+
* @throws \Exception
30+
*/
31+
public function writePresProps(PhpPowerpoint $pPHPPowerPoint = null)
32+
{
33+
// Create XML writer
34+
$objWriter = $this->getXMLWriter();
35+
36+
// XML header
37+
$objWriter->startDocument('1.0','UTF-8','yes');
38+
39+
// p:presentationPr
40+
$objWriter->startElement('p:presentationPr');
41+
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
42+
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
43+
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');
44+
45+
// p:extLst
46+
$objWriter->startElement('p:extLst');
47+
48+
// p:ext
49+
$objWriter->startElement('p:ext');
50+
$objWriter->writeAttribute('uri', '{E76CE94A-603C-4142-B9EB-6D1370010A27}');
51+
52+
// p14:discardImageEditData
53+
$objWriter->startElement('p14:discardImageEditData');
54+
$objWriter->writeAttribute('xmlns:p14', 'http://schemas.microsoft.com/office/powerpoint/2010/main');
55+
$objWriter->writeAttribute('val', '0');
56+
$objWriter->endElement();
57+
58+
// > p:ext
59+
$objWriter->endElement();
60+
61+
// p:ext
62+
$objWriter->startElement('p:ext');
63+
$objWriter->writeAttribute('uri', '{D31A062A-798A-4329-ABDD-BBA856620510}');
64+
65+
// p14:defaultImageDpi
66+
$objWriter->startElement('p14:defaultImageDpi');
67+
$objWriter->writeAttribute('xmlns:p14', 'http://schemas.microsoft.com/office/powerpoint/2010/main');
68+
$objWriter->writeAttribute('val', '220');
69+
$objWriter->endElement();
70+
71+
// > p:ext
72+
$objWriter->endElement();
73+
// > p:extLst
74+
$objWriter->endElement();
75+
// > p:presentationPr
76+
$objWriter->endElement();
77+
78+
return $objWriter->getData();
79+
}
80+
81+
/**
82+
* Write ppt/tableStyles.xml to XML format
83+
*
84+
* @param PhpPowerpoint $pPHPPowerPoint
85+
* @return string XML Output
86+
* @throws \Exception
87+
*/
88+
public function writeTableStyles(PhpPowerpoint $pPHPPowerPoint = null)
89+
{
90+
// Create XML writer
91+
$objWriter = $this->getXMLWriter();
92+
// XML header
93+
$objWriter->startDocument('1.0','UTF-8','yes');
94+
95+
// a:tblStyleLst
96+
$objWriter->startElement('a:tblStyleLst');
97+
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
98+
$objWriter->writeAttribute('def', '{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}');
99+
$objWriter->endElement();
100+
101+
return $objWriter->getData();
102+
}
103+
}

0 commit comments

Comments
 (0)