/** * Test create new instance */ public function testConstruct() { $object = new PhpPresentation(); $slide = $object->getSlide(); $this->assertEquals(new DocumentProperties(), $object->getDocumentProperties()); $this->assertEquals(new DocumentLayout(), $object->getLayout()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->getSlide()); $this->assertEquals(1, count($object->getAllSlides())); $this->assertEquals(0, $object->getIndex($slide)); $this->assertEquals(1, $object->getSlideCount()); $this->assertEquals(0, $object->getActiveSlideIndex()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Iterator', $object->getSlideIterator()); }
protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt) { $this->append('<div class="infoBlk" id="divPhpPresentationInfo">'); $this->append('<dl>'); $this->append('<dt>Number of slides</dt><dd>' . $oPHPPpt->getSlideCount() . '</dd>'); $this->append('<dt>Document Layout Name</dt><dd>' . (empty($oPHPPpt->getLayout()->getDocumentLayout()) ? 'Custom' : $oPHPPpt->getLayout()->getDocumentLayout()) . '</dd>'); $this->append('<dt>Document Layout Height</dt><dd>' . $oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER) . ' mm</dd>'); $this->append('<dt>Document Layout Width</dt><dd>' . $oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER) . ' mm</dd>'); $this->append('<dt>Properties : Category</dt><dd>' . $oPHPPpt->getDocumentProperties()->getCategory() . '</dd>'); $this->append('<dt>Properties : Company</dt><dd>' . $oPHPPpt->getDocumentProperties()->getCompany() . '</dd>'); $this->append('<dt>Properties : Created</dt><dd>' . $oPHPPpt->getDocumentProperties()->getCreated() . '</dd>'); $this->append('<dt>Properties : Creator</dt><dd>' . $oPHPPpt->getDocumentProperties()->getCreator() . '</dd>'); $this->append('<dt>Properties : Description</dt><dd>' . $oPHPPpt->getDocumentProperties()->getDescription() . '</dd>'); $this->append('<dt>Properties : Keywords</dt><dd>' . $oPHPPpt->getDocumentProperties()->getKeywords() . '</dd>'); $this->append('<dt>Properties : Last Modified By</dt><dd>' . $oPHPPpt->getDocumentProperties()->getLastModifiedBy() . '</dd>'); $this->append('<dt>Properties : Modified</dt><dd>' . $oPHPPpt->getDocumentProperties()->getModified() . '</dd>'); $this->append('<dt>Properties : Subject</dt><dd>' . $oPHPPpt->getDocumentProperties()->getSubject() . '</dd>'); $this->append('<dt>Properties : Title</dt><dd>' . $oPHPPpt->getDocumentProperties()->getTitle() . '</dd>'); $this->append('</dl>'); $this->append('</div>'); foreach ($oPHPPpt->getAllSlides() as $oSlide) { $this->append('<div class="infoBlk" id="div' . $oSlide->getHashCode() . 'Info">'); $this->append('<dl>'); $this->append('<dt>HashCode</dt><dd>' . $oSlide->getHashCode() . '</dd>'); $this->append('<dt>Slide Layout</dt><dd>Layout::' . $this->getConstantName('\\PhpOffice\\PhpPresentation\\Slide\\Layout', $oSlide->getSlideLayout()) . '</dd>'); $this->append('<dt>Offset X</dt><dd>' . $oSlide->getOffsetX() . '</dd>'); $this->append('<dt>Offset Y</dt><dd>' . $oSlide->getOffsetY() . '</dd>'); $this->append('<dt>Extent X</dt><dd>' . $oSlide->getExtentX() . '</dd>'); $this->append('<dt>Extent Y</dt><dd>' . $oSlide->getExtentY() . '</dd>'); $oBkg = $oSlide->getBackground(); if ($oBkg instanceof Slide\AbstractBackground) { if ($oBkg instanceof Slide\Background\Color) { $this->append('<dt>Background Color</dt><dd>#' . $oBkg->getColor()->getRGB() . '</dd>'); } if ($oBkg instanceof Slide\Background\Image) { $sBkgImgContents = file_get_contents($oBkg->getPath()); $this->append('<dt>Background Image</dt><dd><img src="data:image/png;base64,' . base64_encode($sBkgImgContents) . '"></dd>'); } } $this->append('</dl>'); $this->append('</div>'); foreach ($oSlide->getShapeCollection() as $oShape) { if ($oShape instanceof Group) { foreach ($oShape->getShapeCollection() as $oShapeChild) { $this->displayShapeInfo($oShapeChild); } } else { $this->displayShapeInfo($oShape); } } } }
/** * Save PhpPresentation to file * * @param string $pFilename * @throws \Exception */ public function save($pFilename) { if (empty($pFilename)) { throw new \Exception("Filename is empty"); } if (!is_null($this->presentation)) { // If $pFilename is php://output or php://stdout, make it a temporary file... $originalFilename = $pFilename; if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { $pFilename = @tempnam('./', 'phppttmp'); if ($pFilename == '') { $pFilename = $originalFilename; } } $writerPartChart = $this->getWriterPart('charts'); if (!$writerPartChart instanceof ObjectsChart) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation\\ObjectsChart'); } $writerPartContent = $this->getWriterPart('content'); if (!$writerPartContent instanceof Content) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation\\Content'); } $writerPartDrawing = $this->getWriterPart('Drawing'); if (!$writerPartDrawing instanceof Drawing) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation\\Drawing'); } $writerPartManifest = $this->getWriterPart('manifest'); if (!$writerPartManifest instanceof Manifest) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation\\Manifest'); } $writerPartMeta = $this->getWriterPart('meta'); if (!$writerPartMeta instanceof Meta) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation\\Meta'); } $writerPartMimetype = $this->getWriterPart('mimetype'); if (!$writerPartMimetype instanceof Mimetype) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation\\Mimetype'); } $writerPartStyles = $this->getWriterPart('styles'); if (!$writerPartStyles instanceof Styles) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Writer\\ODPresentation\\Styles'); } // Create drawing dictionary $this->drawingHashTable->addFromSource($writerPartDrawing->allDrawings($this->presentation)); // Create new ZIP file and open it for writing $objZip = new \ZipArchive(); // Try opening the ZIP file if ($objZip->open($pFilename, \ZIPARCHIVE::OVERWRITE) !== true) { if ($objZip->open($pFilename, \ZIPARCHIVE::CREATE) !== true) { throw new \Exception("Could not open " . $pFilename . " for writing."); } } // Add mimetype to ZIP file //@todo Not in ZIPARCHIVE::CM_STORE mode $objZip->addFromString('mimetype', $writerPartMimetype->writePart()); // Add content.xml to ZIP file $objZip->addFromString('content.xml', $writerPartContent->writePart($this->presentation)); // Add meta.xml to ZIP file $objZip->addFromString('meta.xml', $writerPartMeta->writePart($this->presentation)); // Add styles.xml to ZIP file $objZip->addFromString('styles.xml', $writerPartStyles->writePart($this->presentation)); // Add META-INF/manifest.xml $objZip->addFromString('META-INF/manifest.xml', $writerPartManifest->writePart()); // Add charts foreach ($this->chartArray as $keyChart => $shapeChart) { $arrayFile = $writerPartChart->writePart($shapeChart); foreach ($arrayFile as $file => $content) { if (!empty($content)) { $objZip->addFromString('Object ' . $keyChart . '/' . $file, $content); } } } // Add media $arrMedia = array(); for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { $shape = $this->getDrawingHashTable()->getByIndex($i); if (!$shape instanceof AbstractDrawing) { throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPresentation\\Shape\\AbstractDrawing'); } if ($shape instanceof ShapeDrawing) { if (!in_array(md5($shape->getPath()), $arrMedia)) { $arrMedia[] = md5($shape->getPath()); $imagePath = $shape->getPath(); if (strpos($imagePath, 'zip://') !== false) { $imagePath = substr($imagePath, 6); $imagePathSplitted = explode('#', $imagePath); $imageZip = new \ZipArchive(); $imageZip->open($imagePathSplitted[0]); $imageContents = $imageZip->getFromName($imagePathSplitted[1]); $imageZip->close(); unset($imageZip); } else { $imageContents = file_get_contents($imagePath); } $objZip->addFromString('Pictures/' . md5($shape->getPath()) . '.' . $shape->getExtension(), $imageContents); } } elseif ($shape instanceof MemoryDrawing) { if (!in_array(str_replace(' ', '_', $shape->getIndexedFilename()), $arrMedia)) { $arrMedia[] = str_replace(' ', '_', $shape->getIndexedFilename()); ob_start(); call_user_func($shape->getRenderingFunction(), $shape->getImageResource()); $imageContents = ob_get_contents(); ob_end_clean(); $objZip->addFromString('Pictures/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents); } } } foreach ($this->presentation->getAllSlides() as $keySlide => $oSlide) { // Add background image slide $oBkgImage = $oSlide->getBackground(); if ($oBkgImage instanceof Image) { $objZip->addFromString('Pictures/' . $oBkgImage->getIndexedFilename($keySlide), file_get_contents($oBkgImage->getPath())); } } // Close file if ($objZip->close() === false) { throw new \Exception("Could not close zip file {$pFilename}."); } // If a temporary file was used, copy it to the correct file stream if ($originalFilename != $pFilename) { if (copy($pFilename, $originalFilename) === false) { throw new \Exception("Could not copy temporary zip file {$pFilename} to {$originalFilename}."); } if (@unlink($pFilename) === false) { throw new \Exception('The file ' . $pFilename . ' could not be deleted.'); } } } else { throw new \Exception("PhpPresentation object unassigned."); } }
/** * Write content file to XML format * * @param PhpPresentation $pPhpPresentation * @return string XML Output * @throws \Exception */ public function writePart(PhpPresentation $pPhpPresentation) { // Create XML writer $objWriter = $this->getXMLWriter(); // XML header $objWriter->startDocument('1.0', 'UTF-8'); // office:document-content $objWriter->startElement('office:document-content'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0'); $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:rdfa', 'http://docs.oasis-open.org/opendocument/meta/rdfa#'); $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); $objWriter->writeAttribute('office:version', '1.2'); // office:automatic-styles $objWriter->startElement('office:automatic-styles'); $this->shapeId = 0; $incSlide = 0; foreach ($pPhpPresentation->getAllSlides() as $pSlide) { // Slides $this->writeStyleSlide($objWriter, $pSlide, $incSlide); // Images $shapes = $pSlide->getShapeCollection(); foreach ($shapes as $shape) { // Increment $this->shapeId ++$this->shapeId; // Check type if ($shape instanceof RichText) { $this->writeTxtStyle($objWriter, $shape); } if ($shape instanceof AbstractDrawing) { $this->writeDrawingStyle($objWriter, $shape); } if ($shape instanceof Line) { $this->writeLineStyle($objWriter, $shape); } if ($shape instanceof Table) { $this->writeTableStyle($objWriter, $shape); } if ($shape instanceof Group) { $this->writeGroupStyle($objWriter, $shape); } } $incSlide++; } // Style : Bullet if (!empty($this->arrStyleBullet)) { foreach ($this->arrStyleBullet as $key => $item) { $oStyle = $item['oStyle']; $arrLevel = explode(';', $item['level']); // style:style $objWriter->startElement('text:list-style'); $objWriter->writeAttribute('style:name', 'L_' . $key); foreach ($arrLevel as $level) { if ($level != '') { $oAlign = $item['oAlign_' . $level]; // text:list-level-style-bullet $objWriter->startElement('text:list-level-style-bullet'); $objWriter->writeAttribute('text:level', $level + 1); $objWriter->writeAttribute('text:bullet-char', $oStyle->getBulletChar()); // style:list-level-properties $objWriter->startElement('style:list-level-properties'); if ($oAlign->getIndent() < 0) { $objWriter->writeAttribute('text:space-before', CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - -1 * $oAlign->getIndent()) . 'cm'); $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters(-1 * $oAlign->getIndent()) . 'cm'); } else { $objWriter->writeAttribute('text:space-before', CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - $oAlign->getIndent()) . 'cm'); $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters($oAlign->getIndent()) . 'cm'); } $objWriter->endElement(); // style:text-properties $objWriter->startElement('style:text-properties'); $objWriter->writeAttribute('fo:font-family', $oStyle->getBulletFont()); $objWriter->writeAttribute('style:font-family-generic', 'swiss'); $objWriter->writeAttribute('style:use-window-font-color', 'true'); $objWriter->writeAttribute('fo:font-size', '100'); $objWriter->endElement(); $objWriter->endElement(); } } $objWriter->endElement(); } } // Style : Paragraph if (!empty($this->arrStyleParagraph)) { foreach ($this->arrStyleParagraph as $key => $item) { // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'P_' . $key); $objWriter->writeAttribute('style:family', 'paragraph'); // style:paragraph-properties $objWriter->startElement('style:paragraph-properties'); switch ($item->getAlignment()->getHorizontal()) { case Alignment::HORIZONTAL_LEFT: $objWriter->writeAttribute('fo:text-align', 'left'); break; case Alignment::HORIZONTAL_RIGHT: $objWriter->writeAttribute('fo:text-align', 'right'); break; case Alignment::HORIZONTAL_CENTER: $objWriter->writeAttribute('fo:text-align', 'center'); break; case Alignment::HORIZONTAL_JUSTIFY: $objWriter->writeAttribute('fo:text-align', 'justify'); break; case Alignment::HORIZONTAL_DISTRIBUTED: $objWriter->writeAttribute('fo:text-align', 'justify'); break; default: $objWriter->writeAttribute('fo:text-align', 'left'); break; } $objWriter->endElement(); $objWriter->endElement(); } } // Style : Text : Font if (!empty($this->arrStyleTextFont)) { foreach ($this->arrStyleTextFont as $key => $item) { // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'T_' . $key); $objWriter->writeAttribute('style:family', 'text'); // style:text-properties $objWriter->startElement('style:text-properties'); $objWriter->writeAttribute('fo:color', '#' . $item->getColor()->getRGB()); $objWriter->writeAttribute('fo:font-family', $item->getName()); $objWriter->writeAttribute('fo:font-size', $item->getSize() . 'pt'); // @todo : fo:font-style if ($item->isBold()) { $objWriter->writeAttribute('fo:font-weight', 'bold'); } // @todo : style:text-underline-style $objWriter->endElement(); $objWriter->endElement(); } } $objWriter->endElement(); //=============================================== // Body //=============================================== // office:body $objWriter->startElement('office:body'); // office:presentation $objWriter->startElement('office:presentation'); // Write slides $slideCount = $pPhpPresentation->getSlideCount(); $this->shapeId = 0; for ($i = 0; $i < $slideCount; ++$i) { $pSlide = $pPhpPresentation->getSlide($i); $objWriter->startElement('draw:page'); $name = $pSlide->getName(); if (!is_null($name)) { $objWriter->writeAttribute('draw:name', $name); } $objWriter->writeAttribute('draw:master-page-name', 'Standard'); $objWriter->writeAttribute('draw:style-name', 'stylePage' . $i); // Images $shapes = $pSlide->getShapeCollection(); foreach ($shapes as $shape) { // Increment $this->shapeId ++$this->shapeId; // Check type if ($shape instanceof RichText) { $this->writeShapeTxt($objWriter, $shape); } elseif ($shape instanceof Table) { $this->writeShapeTable($objWriter, $shape); } elseif ($shape instanceof Line) { $this->writeShapeLine($objWriter, $shape); } elseif ($shape instanceof Chart) { $this->writeShapeChart($objWriter, $shape); } elseif ($shape instanceof AbstractDrawing) { $this->writeShapePic($objWriter, $shape); } elseif ($shape instanceof Group) { $this->writeShapeGroup($objWriter, $shape); } } // Slide Note if ($pSlide->getNote() instanceof Note) { $this->writeSlideNote($objWriter, $pSlide->getNote()); } $objWriter->endElement(); } if ($pPhpPresentation->getPresentationProperties()->isLoopContinuouslyUntilEsc()) { $objWriter->startElement('presentation:settings'); $objWriter->writeAttribute('presentation:endless', 'true'); $objWriter->writeAttribute('presentation:pause', 'P0s'); $objWriter->writeAttribute('presentation:mouse-visible', 'false'); $objWriter->endElement(); } // > office:presentation $objWriter->endElement(); // > office:body $objWriter->endElement(); // > office:document-content $objWriter->endElement(); // Return return $objWriter->getData(); }
/** * Write Meta file to XML format * * @param PhpPresentation $pPhpPresentation * @return string XML Output * @throws \Exception */ public function writePart(PhpPresentation $pPhpPresentation) { // Create XML writer $objWriter = $this->getXMLWriter(); // XML header $objWriter->startDocument('1.0', 'UTF-8'); // office:document-meta $objWriter->startElement('office:document-styles'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0'); $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:officeooo', 'http://openoffice.org/2009/office'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:drawooo', 'http://openoffice.org/2010/draw'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('office:version', '1.2'); // Variables $stylePageLayout = $pPhpPresentation->getLayout()->getDocumentLayout(); // office:styles $objWriter->startElement('office:styles'); // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'sPres0'); $objWriter->writeAttribute('style:display-name', 'sPres0'); $objWriter->writeAttribute('style:family', 'presentation'); // style:graphic-properties $objWriter->startElement('style:graphic-properties'); $objWriter->writeAttribute('draw:fill-color', '#ffffff'); // > style:graphic-properties $objWriter->endElement(); // > style:style $objWriter->endElement(); foreach ($pPhpPresentation->getAllSlides() as $slide) { foreach ($slide->getShapeCollection() as $shape) { if ($shape instanceof Table) { $this->writeTableStyle($objWriter, $shape); } elseif ($shape instanceof Group) { $this->writeGroupStyle($objWriter, $shape); } elseif ($shape instanceof RichText) { $this->writeRichTextStyle($objWriter, $shape); } } } // > office:styles $objWriter->endElement(); // office:automatic-styles $objWriter->startElement('office:automatic-styles'); // style:page-layout $objWriter->startElement('style:page-layout'); if (empty($stylePageLayout)) { $objWriter->writeAttribute('style:name', 'sPL0'); } else { $objWriter->writeAttribute('style:name', $stylePageLayout); } // style:page-layout-properties $objWriter->startElement('style:page-layout-properties'); $objWriter->writeAttribute('fo:margin-top', '0cm'); $objWriter->writeAttribute('fo:margin-bottom', '0cm'); $objWriter->writeAttribute('fo:margin-left', '0cm'); $objWriter->writeAttribute('fo:margin-right', '0cm'); $objWriter->writeAttribute('fo:page-width', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($pPhpPresentation->getLayout()->getCX())), 1) . 'cm'); $objWriter->writeAttribute('fo:page-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($pPhpPresentation->getLayout()->getCY())), 1) . 'cm'); if ($pPhpPresentation->getLayout()->getCX() > $pPhpPresentation->getLayout()->getCY()) { $objWriter->writeAttribute('style:print-orientation', 'landscape'); } else { $objWriter->writeAttribute('style:print-orientation', 'portrait'); } $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // office:master-styles $objWriter->startElement('office:master-styles'); // style:master-page $objWriter->startElement('style:master-page'); $objWriter->writeAttribute('style:name', 'Standard'); $objWriter->writeAttribute('style:display-name', 'Standard'); if (empty($stylePageLayout)) { $objWriter->writeAttribute('style:page-layout-name', 'sPL0'); } else { $objWriter->writeAttribute('style:page-layout-name', $stylePageLayout); } $objWriter->writeAttribute('draw:style-name', 'sPres0'); $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // Return return $objWriter->getData(); }
protected function displayPhpPresentationInfo(PhpPresentation $oPHPPpt) { $this->append('<div class="infoBlk" id="divPhpPresentationInfo">'); $this->append('<dl>'); $this->append('<dt>Number of slides</dt><dd>' . $oPHPPpt->getSlideCount() . '</dd>'); $this->append('<dt>Document Layout Height</dt><dd>' . $oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER) . ' mm</dd>'); $this->append('<dt>Document Layout Width</dt><dd>' . $oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER) . ' mm</dd>'); $this->append('<dt>Properties : Category</dt><dd>' . $oPHPPpt->getProperties()->getCategory() . '</dd>'); $this->append('<dt>Properties : Company</dt><dd>' . $oPHPPpt->getProperties()->getCompany() . '</dd>'); $this->append('<dt>Properties : Created</dt><dd>' . $oPHPPpt->getProperties()->getCreated() . '</dd>'); $this->append('<dt>Properties : Creator</dt><dd>' . $oPHPPpt->getProperties()->getCreator() . '</dd>'); $this->append('<dt>Properties : Description</dt><dd>' . $oPHPPpt->getProperties()->getDescription() . '</dd>'); $this->append('<dt>Properties : Keywords</dt><dd>' . $oPHPPpt->getProperties()->getKeywords() . '</dd>'); $this->append('<dt>Properties : Last Modified By</dt><dd>' . $oPHPPpt->getProperties()->getLastModifiedBy() . '</dd>'); $this->append('<dt>Properties : Modified</dt><dd>' . $oPHPPpt->getProperties()->getModified() . '</dd>'); $this->append('<dt>Properties : Subject</dt><dd>' . $oPHPPpt->getProperties()->getSubject() . '</dd>'); $this->append('<dt>Properties : Title</dt><dd>' . $oPHPPpt->getProperties()->getTitle() . '</dd>'); $this->append('</dl>'); $this->append('</div>'); foreach ($oPHPPpt->getAllSlides() as $oSlide) { $this->append('<div class="infoBlk" id="div' . $oSlide->getHashCode() . 'Info">'); $this->append('<dl>'); $this->append('<dt>HashCode</dt><dd>' . $oSlide->getHashCode() . '</dd>'); $this->append('<dt>Slide Layout</dt><dd>Layout::' . $this->getConstantName('\\PhpOffice\\PhpPresentation\\Slide\\Layout', $oSlide->getSlideLayout()) . '</dd>'); $this->append('<dt>Offset X</dt><dd>' . $oSlide->getOffsetX() . '</dd>'); $this->append('<dt>Offset Y</dt><dd>' . $oSlide->getOffsetY() . '</dd>'); $this->append('<dt>Extent X</dt><dd>' . $oSlide->getExtentX() . '</dd>'); $this->append('<dt>Extent Y</dt><dd>' . $oSlide->getExtentY() . '</dd>'); $this->append('</dl>'); $this->append('</div>'); foreach ($oSlide->getShapeCollection() as $oShape) { if ($oShape instanceof Group) { foreach ($oShape->getShapeCollection() as $oShapeChild) { $this->displayShapeInfo($oShapeChild); } } else { $this->displayShapeInfo($oShape); } } } }