示例#1
0
 /**
  * Write presentation relationships to XML format
  *
  * @return string        XML Output
  * @throws \Exception
  */
 public function writePresentationRelationships()
 {
     // Create XML writer
     $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // Relationships
     $objWriter->startElement('Relationships');
     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
     // Relation id
     $relationId = 1;
     $oLayoutPack = new PackDefault();
     $masterSlides = $oLayoutPack->getMasterSlides();
     foreach ($masterSlides as $masterSlide) {
         // Relationship slideMasters/slideMasterX.xml
         $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster', 'slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml');
     }
     // Add slide theme (only one!)
     // Relationship theme/theme1.xml
     $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', 'theme/theme1.xml');
     // Relationships with slides
     $slideCount = $this->getPresentation()->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slides/slide' . ($i + 1) . '.xml');
     }
     $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps', 'presProps.xml');
     $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps', 'viewProps.xml');
     $this->writeRelationship($objWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles', 'tableStyles.xml');
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
示例#2
0
 /**
  * @return \PhpOffice\Common\Adapter\Zip\ZipInterface
  */
 public function render()
 {
     $oLayoutPack = new PackDefault();
     foreach ($oLayoutPack->getMasterSlides() as $masterSlide) {
         // Add slide masters to ZIP file
         $this->oZip->addFromString('ppt/slideMasters/_rels/slideMaster' . $masterSlide['masterid'] . '.xml.rels', $this->writeSlideMasterRelationships($masterSlide['masterid']));
         $this->oZip->addFromString('ppt/slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml', $masterSlide['body']);
     }
     // Add layoutpack relations
     $otherRelations = $oLayoutPack->getMasterSlideRelations();
     foreach ($otherRelations as $otherRelation) {
         if (strpos($otherRelation['target'], 'http://') !== 0) {
             $this->oZip->addFromString($this->absoluteZipPath('ppt/slideMasters/' . $otherRelation['target']), $otherRelation['contents']);
         }
     }
     return $this->oZip;
 }
示例#3
0
 /**
  * @return \PhpOffice\Common\Adapter\Zip\ZipInterface
  * @throws \Exception
  */
 public function render()
 {
     $oLayoutPack = new PackDefault();
     $masterSlides = $oLayoutPack->getMasterSlides();
     foreach ($masterSlides as $masterSlide) {
         // Add themes to ZIP file
         $this->getZip()->addFromString('ppt/theme/_rels/theme' . $masterSlide['masterid'] . '.xml.rels', $this->writeThemeRelationships($masterSlide['masterid']));
         $this->getZip()->addFromString('ppt/theme/theme' . $masterSlide['masterid'] . '.xml', $this->writeTheme($masterSlide['masterid']));
     }
     $otherRelations = $oLayoutPack->getThemeRelations();
     foreach ($otherRelations as $otherRelation) {
         if (strpos($otherRelation['target'], 'http://') !== 0) {
             $this->getZip()->addFromString($this->absoluteZipPath('ppt/theme/' . $otherRelation['target']), $otherRelation['contents']);
         }
     }
     return $this->getZip();
 }
示例#4
0
 /**
  * @return \PhpOffice\Common\Adapter\Zip\ZipInterface
  */
 public function render()
 {
     // Create XML writer
     $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // p:presentation
     $objWriter->startElement('p:presentation');
     $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:sldMasterIdLst
     $objWriter->startElement('p:sldMasterIdLst');
     // Add slide masters
     $relationId = 1;
     $slideMasterId = 2147483648.0;
     $oLayoutPack = new PackDefault();
     $masterSlides = $oLayoutPack->getMasterSlides();
     $masterSlidesCount = count($masterSlides);
     // @todo foreach ($masterSlides as $masterSlide)
     for ($i = 0; $i < $masterSlidesCount; $i++) {
         // p:sldMasterId
         $objWriter->startElement('p:sldMasterId');
         $objWriter->writeAttribute('id', $slideMasterId);
         $objWriter->writeAttribute('r:id', 'rId' . $relationId++);
         $objWriter->endElement();
         // Increase identifier
         $slideMasterId += 12;
     }
     $objWriter->endElement();
     // theme
     $relationId++;
     // p:sldIdLst
     $objWriter->startElement('p:sldIdLst');
     // Write slides
     $slideCount = $this->oPresentation->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         // p:sldId
         $objWriter->startElement('p:sldId');
         $objWriter->writeAttribute('id', $i + 256);
         $objWriter->writeAttribute('r:id', 'rId' . ($i + $relationId));
         $objWriter->endElement();
     }
     $objWriter->endElement();
     // p:sldSz
     $objWriter->startElement('p:sldSz');
     $objWriter->writeAttribute('cx', $this->oPresentation->getLayout()->getCX());
     $objWriter->writeAttribute('cy', $this->oPresentation->getLayout()->getCY());
     if ($this->oPresentation->getLayout()->getDocumentLayout() != DocumentLayout::LAYOUT_CUSTOM) {
         $objWriter->writeAttribute('type', $this->oPresentation->getLayout()->getDocumentLayout());
     }
     $objWriter->endElement();
     // p:notesSz
     $objWriter->startElement('p:notesSz');
     $objWriter->writeAttribute('cx', '6858000');
     $objWriter->writeAttribute('cy', '9144000');
     $objWriter->endElement();
     $objWriter->endElement();
     $this->oZip->addFromString('ppt/presentation.xml', $objWriter->getData());
     // Return
     return $this->oZip;
 }
示例#5
0
 /**
  * @return \PhpOffice\Common\Adapter\Zip\ZipInterface
  * @throws \Exception
  */
 public function render()
 {
     $oLayoutPack = new PowerPoint2007\LayoutPack\PackDefault();
     // Create XML writer
     $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // Types
     $objWriter->startElement('Types');
     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
     // Rels
     $this->writeDefaultContentType($objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml');
     // XML
     $this->writeDefaultContentType($objWriter, 'xml', 'application/xml');
     // Themes
     $masterSlides = $oLayoutPack->getMasterSlides();
     foreach ($masterSlides as $masterSlide) {
         $this->writeOverrideContentType($objWriter, '/ppt/theme/theme' . $masterSlide['masterid'] . '.xml', 'application/vnd.openxmlformats-officedocument.theme+xml');
     }
     // Presentation
     $this->writeOverrideContentType($objWriter, '/ppt/presentation.xml', 'application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml');
     // PptProps
     $this->writeOverrideContentType($objWriter, '/ppt/presProps.xml', 'application/vnd.openxmlformats-officedocument.presentationml.presProps+xml');
     $this->writeOverrideContentType($objWriter, '/ppt/tableStyles.xml', 'application/vnd.openxmlformats-officedocument.presentationml.tableStyles+xml');
     $this->writeOverrideContentType($objWriter, '/ppt/viewProps.xml', 'application/vnd.openxmlformats-officedocument.presentationml.viewProps+xml');
     // DocProps
     $this->writeOverrideContentType($objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml');
     $this->writeOverrideContentType($objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml');
     $this->writeOverrideContentType($objWriter, '/docProps/custom.xml', 'application/vnd.openxmlformats-officedocument.custom-properties+xml');
     // Slide masters
     $masterSlides = $oLayoutPack->getMasterSlides();
     foreach ($masterSlides as $masterSlide) {
         $this->writeOverrideContentType($objWriter, '/ppt/slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml');
     }
     // Slide layouts
     $slideLayouts = $oLayoutPack->getLayouts();
     $numSlideLayouts = count($slideLayouts);
     for ($i = 0; $i < $numSlideLayouts; ++$i) {
         $this->writeOverrideContentType($objWriter, '/ppt/slideLayouts/slideLayout' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml');
     }
     // Slides
     $slideCount = $this->oPresentation->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         $this->writeOverrideContentType($objWriter, '/ppt/slides/slide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml');
         if ($this->oPresentation->getSlide($i)->getNote()->getShapeCollection()->count() > 0) {
             $this->writeOverrideContentType($objWriter, '/ppt/notesSlides/notesSlide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml');
         }
     }
     // Add layoutpack content types
     $otherRelations = $oLayoutPack->getMasterSlideRelations();
     foreach ($otherRelations as $otherRelation) {
         if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
             $this->writeOverrideContentType($objWriter, '/ppt/slideMasters/' . $otherRelation['target'], $otherRelation['contentType']);
         }
     }
     $otherRelations = $oLayoutPack->getThemeRelations();
     foreach ($otherRelations as $otherRelation) {
         if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
             $this->writeOverrideContentType($objWriter, '/ppt/theme/' . $otherRelation['target'], $otherRelation['contentType']);
         }
     }
     $otherRelations = $oLayoutPack->getLayoutRelations();
     foreach ($otherRelations as $otherRelation) {
         if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
             $this->writeOverrideContentType($objWriter, '/ppt/slideLayouts/' . $otherRelation['target'], $otherRelation['contentType']);
         }
     }
     // Add media content-types
     $aMediaContentTypes = array();
     // GIF, JPEG, PNG
     $aMediaContentTypes['gif'] = 'image/gif';
     $aMediaContentTypes['jpg'] = 'image/jpeg';
     $aMediaContentTypes['jpeg'] = 'image/jpeg';
     $aMediaContentTypes['png'] = 'image/png';
     foreach ($aMediaContentTypes as $key => $value) {
         $this->writeDefaultContentType($objWriter, $key, $value);
     }
     // XLSX
     $this->writeDefaultContentType($objWriter, 'xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     // Other media content types
     $mediaCount = $this->getDrawingHashTable()->count();
     for ($i = 0; $i < $mediaCount; ++$i) {
         $extension = '';
         $mimeType = '';
         $shapeIndex = $this->getDrawingHashTable()->getByIndex($i);
         if ($shapeIndex instanceof ShapeChart) {
             // Chart content type
             $this->writeOverrideContentType($objWriter, '/ppt/charts/chart' . $shapeIndex->getImageIndex() . '.xml', 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
         } else {
             if ($shapeIndex instanceof ShapeDrawing) {
                 $extension = strtolower($shapeIndex->getExtension());
                 $mimeType = $this->getImageMimeType($shapeIndex->getPath());
             } elseif ($shapeIndex instanceof MemoryDrawing) {
                 $extension = strtolower($shapeIndex->getMimeType());
                 $extension = explode('/', $extension);
                 $extension = $extension[1];
                 $mimeType = $shapeIndex->getMimeType();
             }
             if (!isset($aMediaContentTypes[$extension])) {
                 $aMediaContentTypes[$extension] = $mimeType;
                 $this->writeDefaultContentType($objWriter, $extension, $mimeType);
             }
         }
     }
     $objWriter->endElement();
     $this->oZip->addFromString('[Content_Types].xml', $objWriter->getData());
     return $this->oZip;
 }