/**
  * Save PHPPowerPoint 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;
             }
         }
         $wPartDrawing = $this->getWriterPart('Drawing');
         if (!$wPartDrawing instanceof Drawing) {
             throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007\\Drawing');
         }
         $wPartContentTypes = $this->getWriterPart('ContentTypes');
         if (!$wPartContentTypes instanceof ContentTypes) {
             throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007\\ContentTypes');
         }
         $wPartRels = $this->getWriterPart('Rels');
         if (!$wPartRels instanceof Rels) {
             throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007\\Rels');
         }
         $wPartDocProps = $this->getWriterPart('DocProps');
         if (!$wPartDocProps instanceof DocProps) {
             throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007\\DocProps');
         }
         $wPartTheme = $this->getWriterPart('Theme');
         if (!$wPartTheme instanceof Theme) {
             throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007\\Theme');
         }
         $wPartPresentation = $this->getWriterPart('Presentation');
         if (!$wPartPresentation instanceof Presentation) {
             throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007\\Presentation');
         }
         $wPartSlide = $this->getWriterPart('Slide');
         if (!$wPartSlide instanceof Slide) {
             throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007\\Slide');
         }
         $wPartChart = $this->getWriterPart('Chart');
         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));
         // 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 [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());
         $objZip->addFromString('ppt/tableStyles.xml', $wPptProps->writeTableStyles());
         $objZip->addFromString('ppt/viewProps.xml', $wPptProps->writeViewProps());
         // 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));
         $masterSlides = $this->getLayoutPack()->getMasterSlides();
         foreach ($masterSlides as $masterSlide) {
             // Add themes to ZIP file
             $objZip->addFromString('ppt/theme/_rels/theme' . $masterSlide['masterid'] . '.xml.rels', $wPartRels->writeThemeRelationships($masterSlide['masterid']));
             $objZip->addFromString('ppt/theme/theme' . $masterSlide['masterid'] . '.xml', utf8_encode($wPartTheme->writeTheme($masterSlide['masterid'])));
             // Add slide masters to ZIP file
             $objZip->addFromString('ppt/slideMasters/_rels/slideMaster' . $masterSlide['masterid'] . '.xml.rels', $wPartRels->writeSlideMasterRelationships($masterSlide['masterid']));
             $objZip->addFromString('ppt/slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml', $masterSlide['body']);
         }
         // Add slide layouts to ZIP file
         $slideLayouts = $this->getLayoutPack()->getLayouts();
         foreach ($slideLayouts as $key => $layout) {
             $objZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . $key . '.xml.rels', $wPartRels->writeSlideLayoutRelationships($key, $layout['masterid']));
             $objZip->addFromString('ppt/slideLayouts/slideLayout' . $key . '.xml', utf8_encode($layout['body']));
         }
         // Add layoutpack relations
         $otherRelations = $this->getLayoutPack()->getMasterSlideRelations();
         foreach ($otherRelations as $otherRelation) {
             if (strpos($otherRelation['target'], 'http://') !== 0) {
                 $objZip->addFromString($this->absoluteZipPath('ppt/slideMasters/' . $otherRelation['target']), $otherRelation['contents']);
             }
         }
         $otherRelations = $this->getLayoutPack()->getThemeRelations();
         foreach ($otherRelations as $otherRelation) {
             if (strpos($otherRelation['target'], 'http://') !== 0) {
                 $objZip->addFromString($this->absoluteZipPath('ppt/theme/' . $otherRelation['target']), $otherRelation['contents']);
             }
         }
         $otherRelations = $this->getLayoutPack()->getLayoutRelations();
         foreach ($otherRelations as $otherRelation) {
             if (strpos($otherRelation['target'], 'http://') !== 0) {
                 $objZip->addFromString($this->absoluteZipPath('ppt/slideLayouts/' . $otherRelation['target']), $otherRelation['contents']);
             }
         }
         // Add presentation to ZIP file
         $objZip->addFromString('ppt/presentation.xml', $wPartPresentation->writePresentation($this->presentation));
         // Add slides (drawings, ...) and slide relationships (drawings, ...)
         for ($i = 0; $i < $this->presentation->getSlideCount(); ++$i) {
             // Add slide
             $objZip->addFromString('ppt/slides/_rels/slide' . ($i + 1) . '.xml.rels', $wPartRels->writeSlideRelationships($this->presentation->getSlide($i)));
             $objZip->addFromString('ppt/slides/slide' . ($i + 1) . '.xml', $wPartSlide->writeSlide($this->presentation->getSlide($i)));
         }
         // Add media
         for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
             $shape = $this->getDrawingHashTable()->getByIndex($i);
             if ($shape instanceof DrawingShape) {
                 $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('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
             } elseif ($shape instanceof MemoryDrawingShape) {
                 ob_start();
                 call_user_func($shape->getRenderingFunction(), $shape->getImageResource());
                 $imageContents = ob_get_contents();
                 ob_end_clean();
                 $objZip->addFromString('ppt/media/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents);
             } elseif ($shape instanceof ChartShape) {
                 $objZip->addFromString('ppt/charts/' . $shape->getIndexedFilename(), $wPartChart->writeChart($shape));
                 // Chart relations?
                 if ($shape->hasIncludedSpreadsheet()) {
                     $objZip->addFromString('ppt/charts/_rels/' . $shape->getIndexedFilename() . '.rels', $wPartRels->writeChartRelationships($shape));
                     $objZip->addFromString('ppt/embeddings/' . $shape->getIndexedFilename() . '.xlsx', $wPartChart->writeSpreadsheet($this->presentation, $shape, $pFilename . '.xlsx'));
                 }
             }
         }
         // 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}.");
             }
             @unlink($pFilename);
         }
     } else {
         throw new \Exception("PHPPowerPoint object unassigned.");
     }
 }
Example #2
0
 /**
  * Save PHPPowerPoint to file
  *
  * @param 	string 		$pFileName
  * @throws 	Exception
  */
 public function save($pFilename = null)
 {
     if (!is_null($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 media
         $slideCount = $this->_presentation->getSlideCount();
         for ($i = 0; $i < $slideCount; ++$i) {
             for ($j = 0; $j < $this->_presentation->getSlide($i)->getShapeCollection()->count(); ++$j) {
                 if ($this->_presentation->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof PHPPowerPoint_Shape_BaseDrawing) {
                     $imgTemp = $this->_presentation->getSlide($i)->getShapeCollection()->offsetGet($j);
                     $objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
                 }
             }
         }
         // Add PHPPowerPoint.xml to the document, which represents a PHP serialized PHPPowerPoint object
         $objZip->addFromString('PHPPowerPoint.xml', $this->_writeSerialized($this->_presentation, $pFilename));
         // Close file
         if ($objZip->close() === false) {
             throw new Exception("Could not close zip file {$pFilename}.");
         }
     } else {
         throw new Exception("PHPPowerPoint object unassigned.");
     }
 }
Example #3
0
 /**
  * Write presentation relationships to XML format
  *
  * @param 	PHPPowerPoint	$pPHPPowerPoint
  * @return 	string 		XML Output
  * @throws 	Exception
  */
 public function writePresentationRelationships(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_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');
     // Relationship slideMasters/slideMaster1.xml
     $this->_writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster', 'slideMasters/slideMaster1.xml');
     // Relationship theme/theme1.xml
     $this->_writeRelationship($objWriter, 2, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', 'theme/theme1.xml');
     // Relationships with slides
     $slideCount = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         $this->_writeRelationship($objWriter, $i + 1 + 2, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slides/slide' . ($i + 1) . '.xml');
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Example #4
0
 /**
  * Write presentation relationships to XML format
  *
  * @param  PHPPowerPoint $pPHPPowerPoint
  * @return string        XML Output
  * @throws \Exception
  */
 public function writePresentationRelationships(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Create XML writer
     $objWriter = $this->getXMLWriter();
     // 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;
     $parentWriter = $this->getParentWriter();
     if ($parentWriter instanceof PowerPoint2007) {
         // Add slide masters
         $masterSlides = $parentWriter->getLayoutPack()->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 = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         $this->writeRelationship($objWriter, $i + $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slides/slide' . ($i + 1) . '.xml');
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Example #5
0
 /**
  * Write Meta file to XML format
  *
  * @param 	PHPPowerPoint $pPHPPowerPoint
  * @return 	string 						XML Output
  * @throws 	Exception
  */
 public function writeMeta(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
     }
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8');
     // office:document-meta
     $objWriter->startElement('office:document-meta');
     $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office: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:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
     $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
     $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:grddl', 'http://www.w3.org/2003/g/data-view#');
     $objWriter->writeAttribute('xmlns:officeooo', 'http://openoffice.org/2009/office');
     $objWriter->writeAttribute('xmlns:drawooo', 'http://openoffice.org/2010/draw');
     $objWriter->writeAttribute('office:version', '1.2');
     // office:meta
     $objWriter->startElement('office:meta');
     // dc:creator
     $objWriter->writeElement('dc:creator', $pPHPPowerPoint->getProperties()->getLastModifiedBy());
     // dc:date
     $objWriter->writeElement('dc:date', gmdate('Y-m-d\\TH:i:s.000', $pPHPPowerPoint->getProperties()->getModified()));
     // dc:description
     $objWriter->writeElement('dc:description', $pPHPPowerPoint->getProperties()->getDescription());
     // dc:subject
     $objWriter->writeElement('dc:subject', $pPHPPowerPoint->getProperties()->getSubject());
     // dc:title
     $objWriter->writeElement('dc:title', $pPHPPowerPoint->getProperties()->getTitle());
     // meta:creation-date
     $objWriter->writeElement('meta:creation-date', gmdate('Y-m-d\\TH:i:s.000', $pPHPPowerPoint->getProperties()->getCreated()));
     // meta:initial-creator
     $objWriter->writeElement('meta:initial-creator', $pPHPPowerPoint->getProperties()->getCreator());
     // meta:keyword
     $objWriter->writeElement('meta:keyword', $pPHPPowerPoint->getProperties()->getKeywords());
     // @todo : Where these properties are written ?
     // $pPHPPowerPoint->getProperties()->getCategory()
     // $pPHPPowerPoint->getProperties()->getCompany()
     $objWriter->endElement();
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Example #6
0
 /**
  * Get an array of all drawings
  *
  * @param 	PHPPowerPoint							$pPHPPowerPoint
  * @return 	PHPPowerPoint_Slide_Drawing[]		All drawings in PHPPowerPoint
  * @throws 	Exception
  */
 public function allDrawings(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Get an array of all drawings
     $aDrawings = array();
     // Loop trough PHPPowerPoint
     $slideCount = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         // Loop trough images and add to array
         $iterator = $pPHPPowerPoint->getSlide($i)->getShapeCollection()->getIterator();
         while ($iterator->valid()) {
             if ($iterator->current() instanceof PHPPowerPoint_Shape_BaseDrawing && !$iterator->current() instanceof PHPPowerPoint_Shape_Table) {
                 $aDrawings[] = $iterator->current();
             }
             $iterator->next();
         }
     }
     return $aDrawings;
 }
 public function export()
 {
     $objPHPPowerPoint = new PHPPowerPoint();
     $objPHPPowerPoint->getProperties()->setCreator("SensorSix");
     $objPHPPowerPoint->getProperties()->setLastModifiedBy("SensorSix");
     $currentSlide = $objPHPPowerPoint->getActiveSlide();
     $this->buildTitleSlide($currentSlide);
     foreach ($this->roadmap->getOrderedRoadmapDecision() as $roadmap_decision) {
         $currentSlide = $objPHPPowerPoint->createSlide();
         $this->buildSlide($currentSlide, $roadmap_decision->getDecision());
     }
     $objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
     $objWriter->save('php://output');
 }
Example #8
0
 public function export()
 {
     $objPHPPowerPoint = new PHPPowerPoint();
     $objPHPPowerPoint->getProperties()->setCreator("Maarten Balliauw");
     $objPHPPowerPoint->getProperties()->setLastModifiedBy("Maarten Balliauw");
     $currentSlide = $objPHPPowerPoint->getActiveSlide();
     foreach ($this->posts as $post) {
         if (!$currentSlide) {
             $currentSlide = $objPHPPowerPoint->createSlide();
         }
         $this->buildSlide($currentSlide, $post);
         $currentSlide = null;
     }
     $objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
     $objWriter->save('php://output');
 }
Example #9
0
 /**
  * Write docProps/core.xml to XML format
  *
  * @param  PHPPowerPoint $pPHPPowerPoint
  * @return string        XML Output
  * @throws Exception
  */
 public function writeDocPropsCore(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
     }
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // cp:coreProperties
     $objWriter->startElement('cp:coreProperties');
     $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
     $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
     $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
     $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
     $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     // dc:creator
     $objWriter->writeElement('dc:creator', $pPHPPowerPoint->getProperties()->getCreator());
     // cp:lastModifiedBy
     $objWriter->writeElement('cp:lastModifiedBy', $pPHPPowerPoint->getProperties()->getLastModifiedBy());
     // dcterms:created
     $objWriter->startElement('dcterms:created');
     $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
     $objWriter->writeRaw(gmdate("Y-m-d\\TH:i:s\\Z", $pPHPPowerPoint->getProperties()->getCreated()));
     $objWriter->endElement();
     // dcterms:modified
     $objWriter->startElement('dcterms:modified');
     $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
     $objWriter->writeRaw(gmdate("Y-m-d\\TH:i:s\\Z", $pPHPPowerPoint->getProperties()->getModified()));
     $objWriter->endElement();
     // dc:title
     $objWriter->writeElement('dc:title', $pPHPPowerPoint->getProperties()->getTitle());
     // dc:description
     $objWriter->writeElement('dc:description', $pPHPPowerPoint->getProperties()->getDescription());
     // dc:subject
     $objWriter->writeElement('dc:subject', $pPHPPowerPoint->getProperties()->getSubject());
     // cp:keywords
     $objWriter->writeElement('cp:keywords', $pPHPPowerPoint->getProperties()->getKeywords());
     // cp:category
     $objWriter->writeElement('cp:category', $pPHPPowerPoint->getProperties()->getCategory());
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Example #10
0
 /**
  * Write slides
  *
  * @param  \PhpOffice\PhpPowerpoint\Shared\XMLWriter $objWriter       XML Writer
  * @param  PHPPowerPoint                  $pPHPPowerPoint
  * @param  int                            $startRelationId
  * @throws \Exception
  */
 private function writeSlides(XMLWriter $objWriter, PHPPowerPoint $pPHPPowerPoint = null, $startRelationId = 2)
 {
     // Write slides
     $slideCount = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         // p:sldId
         $this->writeSlide($objWriter, $i + 256, $i + $startRelationId);
     }
 }
Example #11
0
/**
 * Creates a templated slide
 *
 * @param PHPPowerPoint $objPHPPowerPoint
 * @return PHPPowerPoint_Slide
 */
function createTemplatedSlide(PHPPowerPoint $objPHPPowerPoint)
{
    // Create slide
    $slide = $objPHPPowerPoint->createSlide();
    // Add logo
    $slide->createDrawingShape()->setName('PHPPowerPoint logo')->setDescription('PHPPowerPoint logo')->setPath('./images/phppowerpoint_logo.gif')->setHeight(40)->setOffsetX(10)->setOffsetY(720 - 10 - 40);
    // Return slide
    return $slide;
}
Example #12
0
function ppt_export_dots(&$dots, &$more)
{
    $maps = array();
    $w = 960;
    $h = 720;
    $ppt = new PHPPowerPoint();
    $ppt->getProperties()->setTitle($more['title']);
    $ppt->getProperties()->setCreator("Dotspotting");
    # set title here
    # $slide = $ppt->getActiveSlide();
    $ppt->removeSlideByIndex(0);
    # draw the maps
    $dot_per_slide = 1;
    $img_more = array('width' => $w, 'height' => $h, 'dot_size' => 20);
    if (!$dot_per_slide || count($dots) == 0) {
        $maps[] = maps_png_for_dots($dots, $img_more);
    } else {
        $img_more['dot_size'] = 25;
        $img_more['width'] = $img_more['height'];
        $img_more['img_prefix'] = 'ppt';
        # remember: 1 dot per slide
        $_dots = array();
        foreach ($dots as $dot) {
            $_dots[] = array($dot);
        }
        # See this? It's to prevent Dotspoting from accidentally
        # DOS-ing itself.
        $enable_multigets = $GLOBALS['cfg']['wscompose_enable_multigets'];
        if ($dot_per_slide && count($dots) > $GLOBALS['cfg']['wscompose_max_dots_for_multigets']) {
            $GLOBALS['cfg']['wscompose_enable_multigets'] = 0;
        }
        $maps = maps_png_for_dots_multi($_dots, $img_more);
        $GLOBALS['cfg']['wscompose_enable_multigets'] = $enable_multigets;
    }
    # now draw all the maps...
    $count_maps = count($maps);
    for ($i = 0; $i < $count_maps; $i++) {
        $map = $maps[$i];
        $slide = $ppt->createSlide();
        $shape = $slide->createDrawingShape();
        $shape->setName('map');
        $shape->setDescription('');
        $shape->setPath($map);
        $shape->setWidth($w);
        $shape->setHeight($h);
        $shape->setOffsetX(0);
        $shape->setOffsetY(0);
        if ($dot_per_slide) {
            $dot = $dots[$i];
            if (!$dot['id']) {
                continue;
            }
            $_dot = dots_get_dot($dot['id'], $more['viewer_id']);
            if (!$_dot['id']) {
                continue;
            }
            $shape = $slide->createDrawingShape();
            $shape->setName('map');
            $shape->setDescription('');
            $shape->setPath($map);
            $text = $slide->createRichTextShape();
            $text->setHeight($h);
            $text->setWidth($w - $h);
            $text->setOffsetX($h + 20);
            $text->setOffsetY(0 + 20);
            $align = $text->getAlignment();
            $align->setHorizontal(PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT);
            $cols = array_merge($_dot['index_on'], array('latitude', 'longitude', 'created', 'id'));
            foreach ($cols as $col) {
                $value = trim($dot[$col]);
                if (!$value) {
                    continue;
                }
                $body = $text->createTextRun("{$col}:\n");
                $body->getFont()->setSize(18);
                $body->getFont()->setBold(false);
                # default bold font is not what do say "pretty"
                $body = $text->createTextRun("{$dot[$col]}\n\n");
                $body->getFont()->setSize(14);
                $body->getFont()->setBold(false);
            }
        }
    }
    #
    $writer = PHPPowerPoint_IOFactory::createWriter($ppt, 'PowerPoint2007');
    $writer->save($more['path']);
    $writer = null;
    foreach ($maps as $path) {
        if ($path && !file_exists($path) && !unlink($path)) {
            error_log("[EXPORT] (ppt) failed to unlink {$path}");
        }
    }
    return $more['path'];
}
Example #13
0
 /**
  * Write content types to XML format
  *
  * @param 	PHPPowerPoint $pPHPPowerPoint
  * @return 	string 						XML Output
  * @throws 	Exception
  */
 public function writeContentTypes(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_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');
     // Theme
     $this->_writeOverrideContentType($objWriter, '/ppt/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml');
     // Presentation
     $this->_writeOverrideContentType($objWriter, '/ppt/presentation.xml', 'application/vnd.openxmlformats-officedocument.presentationml.presentation.main+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');
     // Slide master
     $this->_writeOverrideContentType($objWriter, '/ppt/slideMasters/slideMaster1.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml');
     // Slide layouts
     $slideLayouts = $this->getParentWriter()->getLayoutPack()->getLayouts();
     for ($i = 0; $i < count($slideLayouts); ++$i) {
         $this->_writeOverrideContentType($objWriter, '/ppt/slideLayouts/slideLayout' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml');
     }
     // Slides
     $slideCount = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         $this->_writeOverrideContentType($objWriter, '/ppt/slides/slide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml');
     }
     // Add media content-types
     $aMediaContentTypes = array();
     $mediaCount = $this->getParentWriter()->getDrawingHashTable()->count();
     for ($i = 0; $i < $mediaCount; ++$i) {
         $extension = '';
         $mimeType = '';
         if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPPowerPoint_Shape_Drawing) {
             $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
             $mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
         } else {
             if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPPowerPoint_Shape_MemoryDrawing) {
                 $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
                 $extension = explode('/', $extension);
                 $extension = $extension[1];
                 $mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType();
             }
         }
         if (!isset($aMediaContentTypes[$extension])) {
             $aMediaContentTypes[$extension] = $mimeType;
             $this->_writeDefaultContentType($objWriter, $extension, $mimeType);
         }
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Example #14
0
 /**
  * Write Meta file to XML format
  *
  * @param  PHPPowerPoint $pPHPPowerPoint
  * @return string        XML Output
  * @throws \Exception
  */
 public function writePart(PHPPowerPoint $pPHPPowerPoint)
 {
     // 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 = $pPHPPowerPoint->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();
     // draw:gradient
     $arrayGradient = array();
     foreach ($pPHPPowerPoint->getAllSlides() as $slide) {
         foreach ($slide->getShapeCollection() as $shape) {
             if ($shape instanceof Table) {
                 foreach ($shape->getRows() as $row) {
                     foreach ($row->getCells() as $cell) {
                         if ($cell->getFill()->getFillType() == Fill::FILL_GRADIENT_LINEAR) {
                             if (!in_array($cell->getFill()->getHashCode(), $arrayGradient)) {
                                 $objWriter->startElement('draw:gradient');
                                 $objWriter->writeAttribute('draw:name', 'gradient_' . $cell->getFill()->getHashCode());
                                 $objWriter->writeAttribute('draw:display-name', 'gradient_' . $cell->getFill()->getHashCode());
                                 $objWriter->writeAttribute('draw:style', 'linear');
                                 $objWriter->writeAttribute('draw:start-intensity', '100%');
                                 $objWriter->writeAttribute('draw:end-intensity', '100%');
                                 $objWriter->writeAttribute('draw:start-color', '#' . $cell->getFill()->getStartColor()->getRGB());
                                 $objWriter->writeAttribute('draw:end-color', '#' . $cell->getFill()->getEndColor()->getRGB());
                                 $objWriter->writeAttribute('draw:border', '0%');
                                 $objWriter->writeAttribute('draw:angle', $cell->getFill()->getRotation() - 90);
                                 $objWriter->endElement();
                                 $arrayGradient[] = $cell->getFill()->getHashCode();
                             }
                         }
                     }
                 }
             }
         }
     }
     // > 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', String::numberFormat(SharedDrawing::pixelsToCentimeters(SharedDrawing::emuToPixels($pPHPPowerPoint->getLayout()->getCX())), 1) . 'cm');
     $objWriter->writeAttribute('fo:page-height', String::numberFormat(SharedDrawing::pixelsToCentimeters(SharedDrawing::emuToPixels($pPHPPowerPoint->getLayout()->getCY())), 1) . 'cm');
     if ($pPHPPowerPoint->getLayout()->getCX() > $pPHPPowerPoint->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();
 }
Example #15
0
 * @version    ##VERSION##, ##DATE##
 */
/** Error reporting */
error_reporting(E_ALL);
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');
/** PHPPowerPoint */
include 'PHPPowerPoint.php';
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
    define('EOL', PHP_EOL);
} else {
    define('EOL', '<br />');
}
// Create new PHPPowerPoint object
echo date('H:i:s') . ' Create new PHPPowerPoint object' . EOL;
$objPHPPowerPoint = new PHPPowerPoint();
// Set properties
echo date('H:i:s') . ' Set properties' . EOL;
$objPHPPowerPoint->getProperties()->setCreator('Maarten Balliauw')->setLastModifiedBy('Maarten Balliauw')->setTitle('Office 2007 PPTX Test Document')->setSubject('Office 2007 PPTX Test Document')->setDescription('Test document for Office 2007 PPTX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('Test result file');
// Create slide
echo date('H:i:s') . ' Create slide' . EOL;
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
echo date('H:i:s') . ' Create a shape (drawing)' . EOL;
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPowerPoint logo')->setDescription('PHPPowerPoint logo')->setPath('./images/phppowerpoint_logo.gif')->setHeight(36)->setOffsetX(10)->setOffsetY(10);
$shape->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
// Create a shape (text)
echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
$shape = $currentSlide->createRichTextShape()->setHeight(300)->setWidth(600)->setOffsetX(170)->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER);
Example #16
0
	Creates PPT file from images supplied via JSON POST from phaidra+
	- Images downloaded via curl
	- PPT is created
*/
include_once 'external/php/PHPPowerPoint.php';
$_PPT_STORAGE_PATH = 'cache/';
$_SLIDE_SIZE = array('height' => 540, 'width' => 720);
$_DEFAULT_IMG_SIZE = 960;
$_MAX_SLIDES = 50;
$server = '';
$maxExecutionThreshold = 0.8;
$maxExecTime = ini_get('max_execution_time');
$startTime = microtime(true);
date_default_timezone_set('Europe/Vienna');
header('Content-Type: application/json');
$ppt = new PHPPowerPoint();
// getting input
$json = $_POST['slides'];
//file_get_contents('test/powerpoint.json');
//$json = utf8_decode($json);
$json = json_decode($json, true);
$props = $ppt->getProperties();
$props->setCompany('Universitätsbibliothek | Universität Wien');
$props->setCreated(time());
$props->setCreator('Phaidra+');
// creating random directory
if (!is_dir($_PPT_STORAGE_PATH)) {
    mkdir($_PPT_STORAGE_PATH);
    chmod($_PPT_STORAGE_PATH, 0777);
}
if (!isset($_POST['pickup'])) {
Example #17
0
 /**
  * Write Meta file to XML format
  *
  * @param  PHPPowerPoint $pPHPPowerPoint
  * @return string        XML Output
  * @throws \Exception
  */
 public function writePart(PHPPowerPoint $pPHPPowerPoint)
 {
     // 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 = $pPHPPowerPoint->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 ($pPHPPowerPoint->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', String::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($pPHPPowerPoint->getLayout()->getCX())), 1) . 'cm');
     $objWriter->writeAttribute('fo:page-height', String::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::emuToPixels($pPHPPowerPoint->getLayout()->getCY())), 1) . 'cm');
     if ($pPHPPowerPoint->getLayout()->getCX() > $pPHPPowerPoint->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();
 }
Example #18
0
 /**
  * Write Meta file to XML format
  *
  * @param  PHPPowerPoint $pPHPPowerPoint
  * @return string        XML Output
  * @throws Exception
  */
 public function writeStyles(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
     }
     // 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 = $pPHPPowerPoint->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');
     $objWriter->endElement();
     $objWriter->endElement();
     $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', round(PHPPowerPoint_Shared_Drawing::pixelsToCentimeters(PHPPowerPoint_Shared_Drawing::EMUToPixels($pPHPPowerPoint->getLayout()->getCX())), 1) . 'cm');
     $objWriter->writeAttribute('fo:page-height', round(PHPPowerPoint_Shared_Drawing::pixelsToCentimeters(PHPPowerPoint_Shared_Drawing::EMUToPixels($pPHPPowerPoint->getLayout()->getCY())), 1) . 'cm');
     if ($pPHPPowerPoint->getLayout()->getCX() > $pPHPPowerPoint->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();
 }
Example #19
0
 /**
  * Write content file to XML format
  *
  * @param 	PHPPowerPoint $pPHPPowerPoint
  * @return 	string 						XML Output
  * @throws 	Exception
  */
 public function writeContent(PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
     }
     // 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');
     //===============================================
     // Styles
     //===============================================
     $arrStyleBullet = array();
     $arrStyleParagraph = array();
     $arrStyleTextFont = array();
     // office:automatic-styles
     $objWriter->startElement('office:automatic-styles');
     $slideCount = $pPHPPowerPoint->getSlideCount();
     $shapeId = 0;
     for ($i = 0; $i < $slideCount; ++$i) {
         $pSlide = $pPHPPowerPoint->getSlide($i);
         // Images
         $shapes = $pSlide->getShapeCollection();
         foreach ($shapes as $shape) {
             // Increment $shapeId
             ++$shapeId;
             // Check type
             if ($shape instanceof PHPPowerPoint_Shape_RichText) {
                 // style:style
                 $objWriter->startElement('style:style');
                 $objWriter->writeAttribute('style:name', 'gr' . $shapeId);
                 $objWriter->writeAttribute('style:family', 'graphic');
                 $objWriter->writeAttribute('style:parent-style-name', 'standard');
                 // style:graphic-properties
                 $objWriter->startElement('style:graphic-properties');
                 $objWriter->writeAttribute('draw:auto-grow-height', 'true');
                 $objWriter->writeAttribute('fo:wrap-option', 'wrap');
                 $objWriter->endElement();
                 $objWriter->endElement();
                 $paragraphs = $shape->getParagraphs();
                 $paragraphId = 0;
                 foreach ($paragraphs as $paragraph) {
                     ++$paragraphId;
                     // Style des paragraphes
                     if (!isset($arrStyleParagraph[$paragraph->getHashCode()])) {
                         $arrStyleParagraph[$paragraph->getHashCode()] = $paragraph;
                     }
                     // Style des listes
                     if (!isset($arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()])) {
                         $arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['oStyle'] = $paragraph->getBulletStyle();
                         $arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['level'] = '';
                     }
                     if (strpos($arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['level'], ';' . $paragraph->getAlignment()->getLevel()) === false) {
                         $arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['level'] .= ';' . $paragraph->getAlignment()->getLevel();
                         $arrStyleBullet[$paragraph->getBulletStyle()->getHashCode()]['oAlign_' . $paragraph->getAlignment()->getLevel()] = $paragraph->getAlignment();
                     }
                     $richtexts = $paragraph->getRichTextElements();
                     $richtextId = 0;
                     foreach ($richtexts as $richtext) {
                         ++$richtextId;
                         // Not a line break
                         if ($richtext instanceof PHPPowerPoint_Shape_RichText_Run) {
                             // Style des font text
                             if (!isset($arrStyleTextFont[$richtext->getFont()->getHashCode()])) {
                                 $arrStyleTextFont[$richtext->getFont()->getHashCode()] = $richtext->getFont();
                             }
                         }
                     }
                 }
             }
             if ($shape instanceof PHPPowerPoint_Shape_BaseDrawing) {
                 if ($shape->getShadow()->getVisible()) {
                     // style:style
                     $objWriter->startElement('style:style');
                     $objWriter->writeAttribute('style:name', 'gr' . $shapeId);
                     $objWriter->writeAttribute('style:family', 'graphic');
                     $objWriter->writeAttribute('style:parent-style-name', 'standard');
                     // style:graphic-properties
                     $objWriter->startElement('style:graphic-properties');
                     $objWriter->writeAttribute('draw:stroke', 'none');
                     $objWriter->writeAttribute('draw:fill', 'none');
                     $objWriter->writeAttribute('draw:shadow', 'visible');
                     $objWriter->writeAttribute('draw:shadow-color', '#' . $shape->getShadow()->getColor()->getRGB());
                     if ($shape->getShadow()->getDirection() == 0 || $shape->getShadow()->getDirection() == 360) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
                     } elseif ($shape->getShadow()->getDirection() == 45) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 90) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 135) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 180) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
                     } elseif ($shape->getShadow()->getDirection() == 225) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 270) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 315) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     }
                     $objWriter->writeAttribute('draw:shadow-opacity', 100 - $shape->getShadow()->getAlpha() . '%');
                     $objWriter->writeAttribute('style:mirror', 'none');
                     $objWriter->endElement();
                     $objWriter->endElement();
                 }
             }
         }
     }
     // Style : Bullet
     if (!empty($arrStyleBullet)) {
         foreach ($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', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($oAlign->getMarginLeft() - -1 * $oAlign->getIndent()) . 'cm');
                         $objWriter->writeAttribute('text:min-label-width', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters(-1 * $oAlign->getIndent()) . 'cm');
                     } else {
                         $objWriter->writeAttribute('text:space-before', PHPPowerPoint_Shared_Drawing::pixelsToCentimeters($oAlign->getMarginLeft() - $oAlign->getIndent()) . 'cm');
                         $objWriter->writeAttribute('text:min-label-width', PHPPowerPoint_Shared_Drawing::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($arrStyleParagraph)) {
         foreach ($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 PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT:
                     $objWriter->writeAttribute('fo:text-align', 'left');
                     break;
                 case PHPPowerPoint_Style_Alignment::HORIZONTAL_RIGHT:
                     $objWriter->writeAttribute('fo:text-align', 'right');
                     break;
                 case PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER:
                     $objWriter->writeAttribute('fo:text-align', 'center');
                     break;
                 case PHPPowerPoint_Style_Alignment::HORIZONTAL_JUSTIFY:
                     $objWriter->writeAttribute('fo:text-align', 'justify');
                     break;
                 case PHPPowerPoint_Style_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($arrStyleTextFont)) {
         foreach ($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->getBold()) {
                 $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 = $pPHPPowerPoint->getSlideCount();
     $shapeId = 0;
     for ($i = 0; $i < $slideCount; ++$i) {
         $pSlide = $pPHPPowerPoint->getSlide($i);
         $objWriter->startElement('draw:page');
         $objWriter->writeAttribute('draw:name', 'page' . $i);
         $objWriter->writeAttribute('draw:master-page-name', 'Standard');
         // Images
         $shapes = $pSlide->getShapeCollection();
         foreach ($shapes as $shape) {
             // Increment $shapeId
             ++$shapeId;
             // Check type
             if ($shape instanceof PHPPowerPoint_Shape_RichText) {
                 $this->_writeTxt($objWriter, $shape, $shapeId);
             } else {
                 if ($shape instanceof PHPPowerPoint_Shape_BaseDrawing) {
                     $this->_writePic($objWriter, $shape, $shapeId);
                 }
             }
         }
         $objWriter->endElement();
     }
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Example #20
0
 /**
  * Write slides
  *
  * @param 	PHPPowerPoint_Shared_XMLWriter 	$objWriter 		XML Writer
  * @param 	PHPPowerPoint					$pPHPPowerPoint
  * @throws 	Exception
  */
 private function _writeSlides(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint $pPHPPowerPoint = null)
 {
     // Write slides
     $slideCount = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         // p:sldId
         $this->_writeSlide($objWriter, $i + 256, $i + 1 + 2);
     }
 }
Example #21
0
 /**
  * Write chart to XML format
  *
  * @param  PHPPowerPoint             $presentation
  * @param  \PhpOffice\PhpPowerpoint\Shape\Chart $chart
  * @param  string                    $tempName
  * @return string                    String output
  * @throws \Exception
  */
 public function writeSpreadsheet(PHPPowerPoint $presentation, $chart, $tempName)
 {
     // Need output?
     if (!$chart->hasIncludedSpreadsheet()) {
         throw new \Exception('No spreadsheet output is required for the given chart.');
     }
     // Verify \PHPExcel
     if (!class_exists('PHPExcel')) {
         throw new \Exception('PHPExcel has not been loaded. Include PHPExcel.php in your script, e.g. require_once \'PHPExcel.php\'.');
     }
     // Create new spreadsheet
     $workbook = new \PHPExcel();
     // Set properties
     $title = $chart->getTitle()->getText();
     if (strlen($title) == 0) {
         $title = 'Chart';
     }
     $workbook->getProperties()->setCreator($presentation->getProperties()->getCreator())->setLastModifiedBy($presentation->getProperties()->getLastModifiedBy())->setTitle($title);
     // Add chart data
     $sheet = $workbook->setActiveSheetIndex(0);
     $sheet->setTitle('Sheet1');
     // Write series
     $seriesIndex = 0;
     foreach ($chart->getPlotArea()->getType()->getData() as $series) {
         // Title
         $sheet->setCellValueByColumnAndRow(1 + $seriesIndex, 1, $series->getTitle());
         // X-axis
         $axisXData = array_keys($series->getValues());
         for ($i = 0; $i < count($axisXData); $i++) {
             $sheet->setCellValueByColumnAndRow(0, $i + 2, $axisXData[$i]);
         }
         // Y-axis
         $axisYData = array_values($series->getValues());
         for ($i = 0; $i < count($axisYData); $i++) {
             $sheet->setCellValueByColumnAndRow(1 + $seriesIndex, $i + 2, $axisYData[$i]);
         }
         ++$seriesIndex;
     }
     // Save to string
     $writer = \PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
     $writer->save($tempName);
     // Load file in memory
     $returnValue = file_get_contents($tempName);
     @unlink($tempName);
     return $returnValue;
 }
Example #22
0
 /**
  * Save PHPPowerPoint to file
  *
  * @param 	string 		$pFileName
  * @throws 	Exception
  */
 public function save($pFilename = null)
 {
     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;
             }
         }
         // Create drawing dictionary
         $this->_drawingHashTable->addFromSource($this->getWriterPart('Drawing')->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 [Content_Types].xml to ZIP file
         $objZip->addFromString('[Content_Types].xml', $this->getWriterPart('ContentTypes')->writeContentTypes($this->_presentation));
         // Add relationships to ZIP file
         $objZip->addFromString('_rels/.rels', $this->getWriterPart('Rels')->writeRelationships($this->_presentation));
         $objZip->addFromString('ppt/_rels/presentation.xml.rels', $this->getWriterPart('Rels')->writePresentationRelationships($this->_presentation));
         // Add document properties to ZIP file
         $objZip->addFromString('docProps/app.xml', $this->getWriterPart('DocProps')->writeDocPropsApp($this->_presentation));
         $objZip->addFromString('docProps/core.xml', $this->getWriterPart('DocProps')->writeDocPropsCore($this->_presentation));
         // Add theme to ZIP file
         $objZip->addFromString('ppt/theme/theme1.xml', $this->getWriterPart('Theme')->writeTheme($this->_presentation));
         // Add slide master to ZIP file
         $masterSlide = $this->getLayoutPack()->getMasterSlide();
         $objZip->addFromString('ppt/slideMasters/_rels/slideMaster1.xml.rels', $this->getWriterPart('Rels')->writeSlideMasterRelationships());
         $objZip->addFromString('ppt/slideMasters/slideMaster1.xml', $masterSlide['body']);
         // Add slide layouts to ZIP file
         $slideLayouts = $this->getLayoutPack()->getLayouts();
         for ($i = 0; $i < count($slideLayouts); ++$i) {
             $objZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeSlideLayoutRelationships());
             $objZip->addFromString('ppt/slideLayouts/slideLayout' . ($i + 1) . '.xml', $slideLayouts[$i]['body']);
         }
         // Add presentation to ZIP file
         $objZip->addFromString('ppt/presentation.xml', $this->getWriterPart('Presentation')->writePresentation($this->_presentation));
         // Add slides (drawings, ...)
         for ($i = 0; $i < $this->_presentation->getSlideCount(); ++$i) {
             // Add slide
             $objZip->addFromString('ppt/slides/slide' . ($i + 1) . '.xml', $this->getWriterPart('Slide')->writeSlide($this->_presentation->getSlide($i)));
         }
         // Add slide relationships (drawings, ...)
         for ($i = 0; $i < $this->_presentation->getSlideCount(); ++$i) {
             // Add relationships
             $objZip->addFromString('ppt/slides/_rels/slide' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeSlideRelationships($this->_presentation->getSlide($i), $i + 1));
         }
         // Add media
         for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
             if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPPowerPoint_Shape_Drawing) {
                 $imageContents = null;
                 $imagePath = $this->getDrawingHashTable()->getByIndex($i)->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('ppt/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
             } else {
                 if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPPowerPoint_Shape_MemoryDrawing) {
                     ob_start();
                     call_user_func($this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(), $this->getDrawingHashTable()->getByIndex($i)->getImageResource());
                     $imageContents = ob_get_contents();
                     ob_end_clean();
                     $objZip->addFromString('ppt/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
                 }
             }
         }
         // 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}.");
             }
             @unlink($pFilename);
         }
     } else {
         throw new Exception("PHPPowerPoint object unassigned.");
     }
 }
 /**
  * More PHPPowerPoint_Slide instances available?
  *
  * @return boolean
  */
 public function valid()
 {
     return $this->_position < $this->_subject->getSlideCount();
 }
Example #24
0
 /**
  * Write content types to XML format
  *
  * @param  PHPPowerPoint $pPHPPowerPoint
  * @return string        XML Output
  * @throws \Exception
  */
 public function writeContentTypes(PHPPowerPoint $pPHPPowerPoint = null)
 {
     $parentWriter = $this->getParentWriter();
     if (!$parentWriter instanceof PowerPoint2007) {
         throw new \Exception('The $parentWriter is not an instance of \\PhpOffice\\PhpPowerpoint\\Writer\\PowerPoint2007');
     }
     // Create XML writer
     $objWriter = $this->getXMLWriter();
     // 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 = $parentWriter->getLayoutPack()->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');
     // 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');
     // Slide masters
     $masterSlides = $parentWriter->getLayoutPack()->getMasterSlides();
     foreach ($masterSlides as $masterSlide) {
         $this->writeOverrideContentType($objWriter, '/ppt/slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml');
     }
     // Slide layouts
     $slideLayouts = $parentWriter->getLayoutPack()->getLayouts();
     for ($i = 0; $i < count($slideLayouts); ++$i) {
         $this->writeOverrideContentType($objWriter, '/ppt/slideLayouts/slideLayout' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml');
     }
     // Slides
     $slideCount = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         $this->writeOverrideContentType($objWriter, '/ppt/slides/slide' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.presentationml.slide+xml');
     }
     // Add layoutpack content types
     $otherRelations = $parentWriter->getLayoutPack()->getMasterSlideRelations();
     foreach ($otherRelations as $otherRelation) {
         if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
             $this->writeOverrideContentType($objWriter, '/ppt/slideMasters/' . $otherRelation['target'], $otherRelation['contentType']);
         }
     }
     $otherRelations = $parentWriter->getLayoutPack()->getThemeRelations();
     foreach ($otherRelations as $otherRelation) {
         if (strpos($otherRelation['target'], 'http://') !== 0 && $otherRelation['contentType'] != '') {
             $this->writeOverrideContentType($objWriter, '/ppt/theme/' . $otherRelation['target'], $otherRelation['contentType']);
         }
     }
     $otherRelations = $parentWriter->getLayoutPack()->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 = $parentWriter->getDrawingHashTable()->count();
     for ($i = 0; $i < $mediaCount; ++$i) {
         $extension = '';
         $mimeType = '';
         $shapeIndex = $parentWriter->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();
     // Return
     return $objWriter->getData();
 }
Example #25
0
 *
 * @category   PHPPowerPoint
 * @package    PHPPowerPoint
 * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
 * @version    ##VERSION##, ##DATE##
 */
/** Error reporting */
error_reporting(E_ALL);
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');
/** PHPPowerPoint */
include 'PHPPowerPoint.php';
// Create new PHPPowerPoint object
echo date('H:i:s') . " Create new PHPPowerPoint object\n";
$objPHPPowerPoint = new PHPPowerPoint();
// Set properties
echo date('H:i:s') . " Set properties\n";
$objPHPPowerPoint->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2007 PPTX Test Document")->setSubject("Office 2007 PPTX Test Document")->setDescription("Test document for Office 2007 PPTX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file");
// Create slide
echo date('H:i:s') . " Create slide\n";
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
echo date('H:i:s') . " Create a shape (drawing)\n";
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPowerPoint logo')->setDescription('PHPPowerPoint logo')->setPath('./images/phppowerpoint_logo.gif')->setHeight(36)->setOffsetX(10)->setOffsetY(10);
$shape->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
// Create a shape (text)
echo date('H:i:s') . " Create a shape (rich text)\n";
$shape = $currentSlide->createRichTextShape()->setHeight(300)->setWidth(600)->setOffsetX(170)->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER);
Example #26
0
 /**
  * Re-bind parent
  *
  * @param PHPPowerPoint $parent
  * @return PHPPowerPoint_Slide
  */
 public function rebindParent(PHPPowerPoint $parent)
 {
     $this->_parent->removeSlideByIndex($this->_parent->getIndex($this));
     $this->_parent = $parent;
     return $this;
 }
Example #27
0
/**
 * Creates a templated slide
 * 
 * @param PHPPowerPoint $objPHPPowerPoint
 * @return PHPPowerPoint_Slide
 */
function createTemplatedSlide(PHPPowerPoint $objPHPPowerPoint)
{
    // Create slide
    $slide = $objPHPPowerPoint->createSlide();
    // Add background image
    $shape = $slide->createDrawingShape();
    $shape->setName('Background');
    $shape->setDescription('Background');
    $shape->setPath('./images/realdolmen_bg.jpg');
    $shape->setWidth(950);
    $shape->setHeight(720);
    $shape->setOffsetX(0);
    $shape->setOffsetY(0);
    // Add logo
    $shape = $slide->createDrawingShape();
    $shape->setName('PHPPowerPoint logo');
    $shape->setDescription('PHPPowerPoint logo');
    $shape->setPath('./images/phppowerpoint_logo.gif');
    $shape->setHeight(40);
    $shape->setOffsetX(10);
    $shape->setOffsetY(720 - 10 - 40);
    // Return slide
    return $slide;
}