Skip to content

Commit

Permalink
PowerPoint2007 Writer : Keynote incompatibility (CodePlex#237322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Aug 12, 2014
1 parent 321bf4f commit 92ffaf4
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
### Bugfix
- PowerPoint2007 Writer : Powerpoint Repair Error in Office 2010 - @Progi1984 GH-39
- PowerPoint2007 Writer : BUG: Repair Error / Wrong anchor if you don't set vertical alignment different to VERTICAL_BASE - @fregge GH-42
- PowerPoint2007 Writer : Keynote incompatibility - @catrane CP#237322

### Miscellaneous
- QA : Move AbstractType for Chart - @Progi1984
Expand Down
11 changes: 11 additions & 0 deletions src/PhpPowerpoint/Writer/PowerPoint2007.php
Expand Up @@ -28,6 +28,7 @@
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\DocProps;
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Drawing;
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\LayoutPack\PackDefault;
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\PptProps;
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Presentation;
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Rels;
use PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Slide;
Expand Down Expand Up @@ -105,6 +106,7 @@ public function __construct(PHPPowerPoint $pPHPPowerPoint = null)

// Initialise writer parts
$this->writerParts['contenttypes'] = new ContentTypes();
$this->writerParts['pptprops'] = new PptProps();
$this->writerParts['docprops'] = new DocProps();
$this->writerParts['rels'] = new Rels();
$this->writerParts['theme'] = new Theme();
Expand Down Expand Up @@ -190,6 +192,10 @@ public function save($pFilename)
if (!$wPartChart instanceof Chart) {
throw new \Exception('The $parentWriter is not an instance of \PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\Chart');
}
$wPptProps = $this->getWriterPart('PptProps');
if (!$wPptProps instanceof PptProps) {
throw new \Exception('The $parentWriter is not an instance of \PhpOffice\PhpPowerpoint\Writer\PowerPoint2007\PptProps');
}

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

// Add PPT properties and styles to ZIP file - Required for Apple Keynote compatibility.
$objZip->addFromString('ppt/presProps.xml', $wPptProps->writePresProps($this->presentation));
$objZip->addFromString('ppt/tableStyles.xml', $wPptProps->writeTableStyles($this->presentation));

// Add relationships to ZIP file
$objZip->addFromString('_rels/.rels', $wPartRels->writeRelationships());
$objZip->addFromString('ppt/_rels/presentation.xml.rels', $wPartRels->writePresentationRelationships($this->presentation));

// Add document properties to ZIP file
$objZip->addFromString('docProps/app.xml', $wPartDocProps->writeDocPropsApp($this->presentation));
$objZip->addFromString('docProps/core.xml', $wPartDocProps->writeDocPropsCore($this->presentation));
Expand Down
103 changes: 103 additions & 0 deletions src/PhpPowerpoint/Writer/PowerPoint2007/PptProps.php
@@ -0,0 +1,103 @@
<?php
/**
* This file is part of PHPPowerPoint - A pure PHP library for reading and writing
* presentations documents.
*
* PHPPowerPoint is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPPowerPoint
* @copyright 2009-2014 PHPPowerPoint contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpPowerpoint\Writer\PowerPoint2007;

use PhpOffice\PhpPowerpoint\PhpPowerpoint;

class PptProps extends AbstractPart
{
/**
* Write ppt/presProps.xml to XML format
*
* @param PhpPowerpoint $pPHPPowerPoint
* @return string XML Output
* @throws \Exception
*/
public function writePresProps(PhpPowerpoint $pPHPPowerPoint = null)
{
// Create XML writer
$objWriter = $this->getXMLWriter();

// XML header
$objWriter->startDocument('1.0','UTF-8','yes');

// p:presentationPr
$objWriter->startElement('p:presentationPr');
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');

// p:extLst
$objWriter->startElement('p:extLst');

// p:ext
$objWriter->startElement('p:ext');
$objWriter->writeAttribute('uri', '{E76CE94A-603C-4142-B9EB-6D1370010A27}');

// p14:discardImageEditData
$objWriter->startElement('p14:discardImageEditData');
$objWriter->writeAttribute('xmlns:p14', 'http://schemas.microsoft.com/office/powerpoint/2010/main');
$objWriter->writeAttribute('val', '0');
$objWriter->endElement();

// > p:ext
$objWriter->endElement();

// p:ext
$objWriter->startElement('p:ext');
$objWriter->writeAttribute('uri', '{D31A062A-798A-4329-ABDD-BBA856620510}');

// p14:defaultImageDpi
$objWriter->startElement('p14:defaultImageDpi');
$objWriter->writeAttribute('xmlns:p14', 'http://schemas.microsoft.com/office/powerpoint/2010/main');
$objWriter->writeAttribute('val', '220');
$objWriter->endElement();

// > p:ext
$objWriter->endElement();
// > p:extLst
$objWriter->endElement();
// > p:presentationPr
$objWriter->endElement();

return $objWriter->getData();
}

/**
* Write ppt/tableStyles.xml to XML format
*
* @param PhpPowerpoint $pPHPPowerPoint
* @return string XML Output
* @throws \Exception
*/
public function writeTableStyles(PhpPowerpoint $pPHPPowerPoint = null)
{
// Create XML writer
$objWriter = $this->getXMLWriter();
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');

// a:tblStyleLst
$objWriter->startElement('a:tblStyleLst');
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
$objWriter->writeAttribute('def', '{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}');
$objWriter->endElement();

return $objWriter->getData();
}
}

0 comments on commit 92ffaf4

Please sign in to comment.