Esempio n. 1
1
 /**
  * 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)) {
         // 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 AbstractDrawing) {
                     $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.");
     }
 }
Esempio n. 2
0
 public function testTypeBar()
 {
     $seriesData = array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2);
     $oPHPPowerPoint = new PhpPowerpoint();
     $oSlide = $oPHPPowerPoint->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oBar = new Bar();
     $oSeries = new Series('Downloads', $seriesData);
     $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
     $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE));
     $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN));
     $oSeries->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKRED));
     $oSeries->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKYELLOW));
     $oBar->addSeries($oSeries);
     $oShape->getPlotArea()->setType($oBar);
     $oXMLDoc = TestHelperDOCX::getDocument($oPHPPowerPoint, 'PowerPoint2007');
     $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/slides/slide1.xml'));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dPt/c:spPr';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:tx/c:v';
     $this->assertEquals($oSeries->getTitle(), $oXMLDoc->getElement($element, 'ppt/charts/' . $oShape->getIndexedFilename())->nodeValue);
 }
Esempio n. 3
0
 /**
  * Get an array of all drawings
  *
  * @param  PhpPowerpoint                 $pPHPPowerPoint
  * @return \PhpOffice\PhpPowerpoint\Shape\AbstractDrawing[] All drawings in PHPPowerPoint
  * @throws \Exception
  */
 public function allDrawings(PhpPowerpoint $pPHPPowerPoint)
 {
     // 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 AbstractDrawing && !$iterator->current() instanceof Table) {
                 $aDrawings[] = $iterator->current();
             } elseif ($iterator->current() instanceof Group) {
                 $iterator2 = $iterator->current()->getShapeCollection()->getIterator();
                 while ($iterator2->valid()) {
                     if ($iterator2->current() instanceof AbstractDrawing && !$iterator2->current() instanceof Table) {
                         $aDrawings[] = $iterator2->current();
                     }
                     $iterator2->next();
                 }
             }
             $iterator->next();
         }
     }
     return $aDrawings;
 }
Esempio n. 4
0
 public function testParent()
 {
     $object = new Note();
     $this->assertNull($object->getParent());
     $oPhpPowerpoint = new PhpPowerpoint();
     $oSlide = $oPhpPowerpoint->createSlide();
     $oSlide->setNote($object);
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->getParent());
 }
Esempio n. 5
0
 public function testCustomDocumentLayout()
 {
     $phpPowerPoint = new PhpPowerpoint();
     $oDocumentLayout = new DocumentLayout();
     $oDocumentLayout->setDocumentLayout(array('cx' => rand(1, 100), 'cy' => rand(1, 100)));
     $phpPowerPoint->setLayout($oDocumentLayout);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $element = "/office:document-styles/office:automatic-styles/style:page-layout";
     $this->assertTrue($pres->elementExists($element, 'styles.xml'));
     $this->assertEquals('sPL0', $pres->getElementAttribute($element, 'style:name', 'styles.xml'));
     $element = "/office:document-styles/office:master-styles/style:master-page";
     $this->assertTrue($pres->elementExists($element, 'styles.xml'));
     $this->assertEquals('sPL0', $pres->getElementAttribute($element, 'style:page-layout-name', 'styles.xml'));
 }
Esempio n. 6
0
 public function testGroup()
 {
     $oPhpPowerPoint = new PhpPowerpoint();
     $oSlide = $oPhpPowerPoint->getActiveSlide();
     $oGroup = $oSlide->createGroup();
     $oDrawing = new Drawing();
     $this->assertInternalType('array', $oDrawing->allDrawings($oPhpPowerPoint));
     $this->assertEmpty($oDrawing->allDrawings($oPhpPowerPoint));
     $oGroup->createDrawingShape();
     $oGroup->createDrawingShape();
     $oGroup->createDrawingShape();
     $this->assertInternalType('array', $oDrawing->allDrawings($oPhpPowerPoint));
     $this->assertCount(3, $oDrawing->allDrawings($oPhpPowerPoint));
 }
Esempio n. 7
0
 public function testMemoryDrawing()
 {
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $oShape = new MemoryDrawing();
     $gdImage = @imagecreatetruecolor(140, 20);
     $textColor = imagecolorallocate($gdImage, 255, 255, 255);
     imagestring($gdImage, 1, 5, 5, 'Created with PHPPowerPoint', $textColor);
     $oShape->setImageResource($gdImage)->setRenderingFunction(MemoryDrawing::RENDERING_JPEG)->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
     $oSlide->addShape($oShape);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $element = '/manifest:manifest/manifest:file-entry[5]';
     $this->assertTrue($pres->elementExists($element, 'META-INF/manifest.xml'));
     $this->assertEquals('Pictures/' . $oShape->getIndexedFilename(), $pres->getElementAttribute($element, 'manifest:full-path', 'META-INF/manifest.xml'));
 }
Esempio n. 8
0
 /**
  * Write presentation relationships to XML format
  *
  * @param  PhpPowerpoint $pPHPPowerPoint
  * @return string        XML Output
  * @throws \Exception
  */
 public function writePresentationRelationships(PhpPowerpoint $pPHPPowerPoint)
 {
     // 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, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slides/slide' . ($i + 1) . '.xml');
     }
     $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps', 'presProps.xml');
     $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps', 'viewProps.xml');
     $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles', 'tableStyles.xml');
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
 /**
  * Test save
  */
 public function testSave()
 {
     $filename = tempnam(sys_get_temp_dir(), 'PHPPowerPoint');
     $imageFile = PHPPOWERPOINT_TESTS_BASE_DIR . '/resources/images/PHPPowerPointLogo.png';
     $phpPowerPoint = new PhpPowerpoint();
     $slide = $phpPowerPoint->getActiveSlide();
     $slide->createRichTextShape();
     $slide->createLineShape(10, 10, 10, 10);
     $slide->createChartShape()->getPlotArea()->setType(new \PhpOffice\PhpPowerpoint\Shape\Chart\Type\Bar3D());
     $slide->createDrawingShape()->setName('Drawing')->setPath($imageFile);
     $slide->createTableShape()->createRow();
     $object = new PowerPoint2007($phpPowerPoint);
     $object->save($filename);
     $this->assertTrue(file_exists($filename));
     unlink($filename);
 }
Esempio n. 10
0
 /**
  */
 public function testMethod()
 {
     $oPHPPowerPoint = new PhpPowerpoint();
     $oPHPPowerPoint->addSlide(new Slide());
     $object = new Iterator($oPHPPowerPoint);
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->current());
     $this->assertEquals(0, $object->key());
     $this->assertNull($object->next());
     $this->assertEquals(1, $object->key());
     $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Slide', $object->current());
     $this->assertTrue($object->valid());
     $this->assertNull($object->next());
     $this->assertFalse($object->valid());
     $this->assertNull($object->rewind());
     $this->assertEquals(0, $object->key());
 }
Esempio n. 11
0
 public function testTypeArea()
 {
     $seriesData = array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2);
     $oPHPPowerPoint = new PhpPowerpoint();
     $oSlide = $oPHPPowerPoint->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oArea = new Area();
     $oSeries = new Series('Downloads', $seriesData);
     $oSeries->getFill()->setStartColor(new Color('FFAABBCC'));
     $oArea->addSeries($oSeries);
     $oShape->getPlotArea()->setType($oArea);
     $oXMLDoc = TestHelperDOCX::getDocument($oPHPPowerPoint, 'PowerPoint2007');
     $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/slides/slide1.xml'));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:areaChart';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $element = '/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
 }
Esempio n. 12
0
 public function testChartArea()
 {
     $oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
     $oSeries->getFill()->setStartColor(new Color('FF93A9CE'));
     $oArea = new Area();
     $oArea->addSeries($oSeries);
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $oChart = $oSlide->createChartShape();
     $oChart->getPlotArea()->setType($oArea);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $element = '/office:document-content/office:body/office:chart/chart:chart';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('chart:area', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));
     $element = '/office:document-content/office:body/office:chart/chart:chart/chart:plot-area/chart:series';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('chart:area', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleSeries0\']/style:graphic-properties';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertFalse($pres->attributeElementExists($element, 'draw:fill', 'Object 1/content.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'draw:fill-color', 'Object 1/content.xml'));
     $this->assertEquals('#93A9CE', $pres->getElementAttribute($element, 'draw:fill-color', 'Object 1/content.xml'));
 }
Esempio n. 13
0
 public function testChartBarHorizontal()
 {
     $oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
     $oSeries->setShowSeriesName(true);
     $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8'));
     $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFAB4744'));
     $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8AA64F'));
     $oBar = new Bar();
     $oBar->setBarDirection(Bar::DIRECTION_HORIZONTAL);
     $oBar->addSeries($oSeries);
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $oChart = $oSlide->createChartShape();
     $oChart->getPlotArea()->setType($oBar);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $element = '/office:document-content/office:body/office:chart/chart:chart';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('chart:bar', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePlotArea\']/style:chart-properties';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $this->assertEquals('true', $pres->getElementAttribute($element, 'chart:vertical', 'Object 1/content.xml'));
     $this->assertFalse($pres->attributeElementExists($element, 'chart:three-dimensional', 'Object 1/content.xml'));
     $this->assertFalse($pres->attributeElementExists($element, 'chart:right-angled-axes', 'Object 1/content.xml'));
 }
 protected function displayPhpPowerpointInfo(PhpPowerpoint $oPHPPpt)
 {
     $this->append('<div class="infoBlk" id="divPhpPowerpointInfo">');
     $this->append('<dl>');
     $this->append('<dt>Number of slides</dt><dd>' . $oPHPPpt->getSlideCount() . '</dd>');
     $this->append('<dt>Document Layout Height</dt><dd>' . $oPHPPpt->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER) . ' mm</dd>');
     $this->append('<dt>Document Layout Width</dt><dd>' . $oPHPPpt->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER) . ' mm</dd>');
     $this->append('<dt>Properties : Category</dt><dd>' . $oPHPPpt->getProperties()->getCategory() . '</dd>');
     $this->append('<dt>Properties : Company</dt><dd>' . $oPHPPpt->getProperties()->getCompany() . '</dd>');
     $this->append('<dt>Properties : Created</dt><dd>' . $oPHPPpt->getProperties()->getCreated() . '</dd>');
     $this->append('<dt>Properties : Creator</dt><dd>' . $oPHPPpt->getProperties()->getCreator() . '</dd>');
     $this->append('<dt>Properties : Description</dt><dd>' . $oPHPPpt->getProperties()->getDescription() . '</dd>');
     $this->append('<dt>Properties : Keywords</dt><dd>' . $oPHPPpt->getProperties()->getKeywords() . '</dd>');
     $this->append('<dt>Properties : Last Modified By</dt><dd>' . $oPHPPpt->getProperties()->getLastModifiedBy() . '</dd>');
     $this->append('<dt>Properties : Modified</dt><dd>' . $oPHPPpt->getProperties()->getModified() . '</dd>');
     $this->append('<dt>Properties : Subject</dt><dd>' . $oPHPPpt->getProperties()->getSubject() . '</dd>');
     $this->append('<dt>Properties : Title</dt><dd>' . $oPHPPpt->getProperties()->getTitle() . '</dd>');
     $this->append('</dl>');
     $this->append('</div>');
     foreach ($oPHPPpt->getAllSlides() as $oSlide) {
         $this->append('<div class="infoBlk" id="div' . $oSlide->getHashCode() . 'Info">');
         $this->append('<dl>');
         $this->append('<dt>HashCode</dt><dd>' . $oSlide->getHashCode() . '</dd>');
         $this->append('<dt>Slide Layout</dt><dd>' . $oSlide->getSlideLayout() . '</dd>');
         $this->append('<dt>Offset X</dt><dd>' . $oSlide->getOffsetX() . '</dd>');
         $this->append('<dt>Offset Y</dt><dd>' . $oSlide->getOffsetY() . '</dd>');
         $this->append('<dt>Extent X</dt><dd>' . $oSlide->getExtentX() . '</dd>');
         $this->append('<dt>Extent Y</dt><dd>' . $oSlide->getExtentY() . '</dd>');
         $this->append('</dl>');
         $this->append('</div>');
         foreach ($oSlide->getShapeCollection() as $oShape) {
             if ($oShape instanceof Group) {
                 foreach ($oShape->getShapeCollection() as $oShapeChild) {
                     $this->displayShapeInfo($oShapeChild);
                 }
             } else {
                 $this->displayShapeInfo($oShape);
             }
         }
     }
 }
Esempio n. 15
0
<?php

include_once 'Sample_Header.php';
use PhpOffice\PhpPowerpoint\PhpPowerpoint;
use PhpOffice\PhpPowerpoint\Style\Alignment;
use PhpOffice\PhpPowerpoint\Style\Color;
// 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('PHPOffice')->setLastModifiedBy('PHPPowerPoint Team')->setTitle('Sample 01 Title')->setSubject('Sample 01 Subject')->setDescription('Sample 01 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
// 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('./resources/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(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
$textRun->getFont()->setBold(true)->setSize(60)->setColor(new Color('FFE06B20'));
// Save file
echo write($objPHPPowerPoint, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}
<?php

include_once 'Sample_Header.php';
use PhpOffice\PhpPowerpoint\PhpPowerpoint;
use PhpOffice\PhpPowerpoint\Style\Alignment;
use PhpOffice\PhpPowerpoint\Style\Color;
use PhpOffice\PhpPowerpoint\IOFactory;
// 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('PHPOffice')->setLastModifiedBy('PHPPowerPoint Team')->setTitle('Sample 03 Title')->setSubject('Sample 03 Subject')->setDescription('Sample 03 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
// 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('./resources/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(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
$textRun->getFont()->setBold(true)->setSize(60)->setColor(new Color('FFE06B20'));
// Save serialized file
$basename = basename(__FILE__, '.php');
echo date('H:i:s') . ' Write to serialized format' . EOL;
$objWriter = IOFactory::createWriter($objPHPPowerPoint, 'Serialized');
function fnSlide_Bar3DHorizontal(PhpPowerpoint $objPHPPowerPoint)
{
    global $oFill;
    global $oShadow;
    // Create a bar chart (that should be inserted in a shape)
    echo date('H:i:s') . ' Create a horizontal bar chart (that should be inserted in a chart shape) ' . EOL;
    $bar3DChartHorz = clone $objPHPPowerPoint->getSlide(5)->getShapeCollection()->offsetGet(1)->getPlotArea()->getType();
    $bar3DChartHorz->setBarDirection(Bar3D::DIRECTION_HORIZONTAL);
    // Create templated slide
    echo EOL . date('H:i:s') . ' Create templated slide' . EOL;
    $currentSlide = createTemplatedSlide($objPHPPowerPoint);
    // Create a shape (chart)
    echo date('H:i:s') . ' Create a shape (chart)' . EOL;
    $shape = $currentSlide->createChartShape();
    $shape->setName('PHPPowerPoint Monthly Downloads')->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
    $shape->setShadow($oShadow);
    $shape->setFill($oFill);
    $shape->getBorder()->setLineStyle(Border::LINE_SINGLE);
    $shape->getTitle()->setText('PHPPowerPoint Monthly Downloads');
    $shape->getTitle()->getFont()->setItalic(true);
    $shape->getTitle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
    $shape->getPlotArea()->getAxisX()->setTitle('Month');
    $shape->getPlotArea()->getAxisY()->setTitle('Downloads');
    $shape->getPlotArea()->setType($bar3DChartHorz);
    $shape->getView3D()->setRightAngleAxes(true);
    $shape->getView3D()->setRotationX(20);
    $shape->getView3D()->setRotationY(20);
    $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
    $shape->getLegend()->getFont()->setItalic(true);
}
 /**
  * Test set active slide index exception
  *
  * @expectedException Exception
  * @expectedExceptionMessage Active slide index is out of bounds.
  */
 public function testSetActiveSlideIndexException()
 {
     $object = new PhpPowerpoint();
     $object->setActiveSlideIndex(1);
 }
Esempio n. 19
0
 /**
  * Write content 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-content
     $objWriter->startElement('office:document-content');
     $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
     $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
     $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
     $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
     $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
     $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
     $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
     $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
     $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
     $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
     $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
     $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
     $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
     $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
     $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
     $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
     $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
     $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
     $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
     $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
     $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
     $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
     $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
     $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0');
     $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0');
     $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
     $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
     $objWriter->writeAttribute('xmlns:rdfa', 'http://docs.oasis-open.org/opendocument/meta/rdfa#');
     $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
     $objWriter->writeAttribute('office:version', '1.2');
     // office:automatic-styles
     $objWriter->startElement('office:automatic-styles');
     $this->shapeId = 0;
     $incSlide = 0;
     foreach ($pPHPPowerPoint->getAllSlides() as $pSlide) {
         // Slides
         $this->writeStyleSlide($objWriter, $pSlide, $incSlide);
         // Images
         $shapes = $pSlide->getShapeCollection();
         foreach ($shapes as $shape) {
             // Increment $this->shapeId
             ++$this->shapeId;
             // Check type
             if ($shape instanceof RichText) {
                 $this->writeTxtStyle($objWriter, $shape);
             }
             if ($shape instanceof AbstractDrawing) {
                 $this->writeDrawingStyle($objWriter, $shape);
             }
             if ($shape instanceof Line) {
                 $this->writeLineStyle($objWriter, $shape);
             }
             if ($shape instanceof Table) {
                 $this->writeTableStyle($objWriter, $shape);
             }
             if ($shape instanceof Group) {
                 $this->writeGroupStyle($objWriter, $shape);
             }
         }
         $incSlide++;
     }
     // Style : Bullet
     if (!empty($this->arrStyleBullet)) {
         foreach ($this->arrStyleBullet as $key => $item) {
             $oStyle = $item['oStyle'];
             $arrLevel = explode(';', $item['level']);
             // style:style
             $objWriter->startElement('text:list-style');
             $objWriter->writeAttribute('style:name', 'L_' . $key);
             foreach ($arrLevel as $level) {
                 if ($level != '') {
                     $oAlign = $item['oAlign_' . $level];
                     // text:list-level-style-bullet
                     $objWriter->startElement('text:list-level-style-bullet');
                     $objWriter->writeAttribute('text:level', $level + 1);
                     $objWriter->writeAttribute('text:bullet-char', $oStyle->getBulletChar());
                     // style:list-level-properties
                     $objWriter->startElement('style:list-level-properties');
                     if ($oAlign->getIndent() < 0) {
                         $objWriter->writeAttribute('text:space-before', CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - -1 * $oAlign->getIndent()) . 'cm');
                         $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters(-1 * $oAlign->getIndent()) . 'cm');
                     } else {
                         $objWriter->writeAttribute('text:space-before', CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - $oAlign->getIndent()) . 'cm');
                         $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters($oAlign->getIndent()) . 'cm');
                     }
                     $objWriter->endElement();
                     // style:text-properties
                     $objWriter->startElement('style:text-properties');
                     $objWriter->writeAttribute('fo:font-family', $oStyle->getBulletFont());
                     $objWriter->writeAttribute('style:font-family-generic', 'swiss');
                     $objWriter->writeAttribute('style:use-window-font-color', 'true');
                     $objWriter->writeAttribute('fo:font-size', '100');
                     $objWriter->endElement();
                     $objWriter->endElement();
                 }
             }
             $objWriter->endElement();
         }
     }
     // Style : Paragraph
     if (!empty($this->arrStyleParagraph)) {
         foreach ($this->arrStyleParagraph as $key => $item) {
             // style:style
             $objWriter->startElement('style:style');
             $objWriter->writeAttribute('style:name', 'P_' . $key);
             $objWriter->writeAttribute('style:family', 'paragraph');
             // style:paragraph-properties
             $objWriter->startElement('style:paragraph-properties');
             switch ($item->getAlignment()->getHorizontal()) {
                 case Alignment::HORIZONTAL_LEFT:
                     $objWriter->writeAttribute('fo:text-align', 'left');
                     break;
                 case Alignment::HORIZONTAL_RIGHT:
                     $objWriter->writeAttribute('fo:text-align', 'right');
                     break;
                 case Alignment::HORIZONTAL_CENTER:
                     $objWriter->writeAttribute('fo:text-align', 'center');
                     break;
                 case Alignment::HORIZONTAL_JUSTIFY:
                     $objWriter->writeAttribute('fo:text-align', 'justify');
                     break;
                 case Alignment::HORIZONTAL_DISTRIBUTED:
                     $objWriter->writeAttribute('fo:text-align', 'justify');
                     break;
                 default:
                     $objWriter->writeAttribute('fo:text-align', 'left');
                     break;
             }
             $objWriter->endElement();
             $objWriter->endElement();
         }
     }
     // Style : Text : Font
     if (!empty($this->arrStyleTextFont)) {
         foreach ($this->arrStyleTextFont as $key => $item) {
             // style:style
             $objWriter->startElement('style:style');
             $objWriter->writeAttribute('style:name', 'T_' . $key);
             $objWriter->writeAttribute('style:family', 'text');
             // style:text-properties
             $objWriter->startElement('style:text-properties');
             $objWriter->writeAttribute('fo:color', '#' . $item->getColor()->getRGB());
             $objWriter->writeAttribute('fo:font-family', $item->getName());
             $objWriter->writeAttribute('fo:font-size', $item->getSize() . 'pt');
             // @todo : fo:font-style
             if ($item->isBold()) {
                 $objWriter->writeAttribute('fo:font-weight', 'bold');
             }
             // @todo : style:text-underline-style
             $objWriter->endElement();
             $objWriter->endElement();
         }
     }
     $objWriter->endElement();
     //===============================================
     // Body
     //===============================================
     // office:body
     $objWriter->startElement('office:body');
     // office:presentation
     $objWriter->startElement('office:presentation');
     // Write slides
     $slideCount = $pPHPPowerPoint->getSlideCount();
     $this->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');
         $objWriter->writeAttribute('draw:style-name', 'stylePage' . $i);
         // Images
         $shapes = $pSlide->getShapeCollection();
         foreach ($shapes as $shape) {
             // Increment $this->shapeId
             ++$this->shapeId;
             // Check type
             if ($shape instanceof RichText) {
                 $this->writeShapeTxt($objWriter, $shape);
             } elseif ($shape instanceof Table) {
                 $this->writeShapeTable($objWriter, $shape);
             } elseif ($shape instanceof Line) {
                 $this->writeShapeLine($objWriter, $shape);
             } elseif ($shape instanceof Chart) {
                 $this->writeShapeChart($objWriter, $shape);
             } elseif ($shape instanceof AbstractDrawing) {
                 $this->writeShapePic($objWriter, $shape);
             } elseif ($shape instanceof Group) {
                 $this->writeShapeGroup($objWriter, $shape);
             }
         }
         // Slide Note
         if ($pSlide->getNote() instanceof Note) {
             $this->writeSlideNote($objWriter, $pSlide->getNote());
         }
         $objWriter->endElement();
     }
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Esempio n. 20
0
 public function testLegend()
 {
     $oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
     $oSeries->setShowSeriesName(true);
     $oLine = new Line();
     $oLine->addSeries($oSeries);
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $oChart = $oSlide->createChartShape();
     $oChart->getPlotArea()->setType($oLine);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $element = '/office:document-content/office:body/office:chart/chart:chart/chart:legend';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $element = '/office:document-content/office:body/office:chart/chart:chart/table:table/table:table-header-rows';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $element = '/office:document-content/office:body/office:chart/chart:chart/table:table/table:table-header-rows/table:table-row';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $element = '/office:document-content/office:body/office:chart/chart:chart/table:table/table:table-header-rows/table:table-row/table:table-cell';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
     $element = '/office:document-content/office:body/office:chart/chart:chart/table:table/table:table-header-rows/table:table-row/table:table-cell[@office:value-type=\'string\']';
     $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
 }
Esempio n. 21
0
 public function testTransition()
 {
     $value = rand(1000, 5000);
     $oTransition = new Transition();
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePage0\']/style:drawing-page-properties';
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $this->assertTrue($pres->elementExists($element, 'content.xml'));
     $this->assertFalse($pres->attributeElementExists($element, 'presentation:duration', 'content.xml'));
     $oTransition->setTimeTrigger(true, $value);
     $oSlide->setTransition($oTransition);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $this->assertTrue($pres->elementExists($element, 'content.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'presentation:duration', 'content.xml'));
     $this->assertStringStartsWith('PT', $pres->getElementAttribute($element, 'presentation:duration', 'content.xml'));
     $this->assertStringEndsWith('S', $pres->getElementAttribute($element, 'presentation:duration', 'content.xml'));
     $this->assertContains(number_format($value / 1000, 6, '.', ''), $pres->getElementAttribute($element, 'presentation:duration', 'content.xml'));
     $this->assertContains('automatic', $pres->getElementAttribute($element, 'presentation:transition-type', 'content.xml'));
     $oTransition->setSpeed(Transition::SPEED_FAST);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $this->assertContains('fast', $pres->getElementAttribute($element, 'presentation:transition-speed', 'content.xml'));
     $oTransition->setSpeed(Transition::SPEED_MEDIUM);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $this->assertContains('medium', $pres->getElementAttribute($element, 'presentation:transition-speed', 'content.xml'));
     $oTransition->setSpeed(Transition::SPEED_SLOW);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $this->assertContains('slow', $pres->getElementAttribute($element, 'presentation:transition-speed', 'content.xml'));
     $rcTransition = new \ReflectionClass('PhpOffice\\PhpPowerpoint\\Slide\\Transition');
     $arrayConstants = $rcTransition->getConstants();
     foreach ($arrayConstants as $key => $value) {
         if (strpos($key, 'TRANSITION_') !== 0) {
             continue;
         }
         $oTransition->setTransitionType($rcTransition->getConstant($key));
         $oSlide->setTransition($oTransition);
         $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
         switch ($key) {
             case 'TRANSITION_BLINDS_HORIZONTAL':
                 $this->assertContains('horizontal-stripes', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_BLINDS_VERTICAL':
                 $this->assertContains('vertical-stripes', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_CHECKER_HORIZONTAL':
                 $this->assertContains('horizontal-checkerboard', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_CHECKER_VERTICAL':
                 $this->assertContains('vertical-checkerboard', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_CIRCLE_HORIZONTAL':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_CIRCLE_VERTICAL':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COMB_HORIZONTAL':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COMB_VERTICAL':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_DOWN':
                 $this->assertContains('uncover-to-bottom', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_LEFT':
                 $this->assertContains('uncover-to-left', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_LEFT_DOWN':
                 $this->assertContains('uncover-to-lowerleft', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_LEFT_UP':
                 $this->assertContains('uncover-to-upperleft', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_RIGHT':
                 $this->assertContains('uncover-to-right', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_RIGHT_DOWN':
                 $this->assertContains('uncover-to-lowerright', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_RIGHT_UP':
                 $this->assertContains('uncover-to-upperright', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_COVER_UP':
                 $this->assertContains('uncover-to-top', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_CUT':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_DIAMOND':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_DISSOLVE':
                 $this->assertContains('dissolve', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_FADE':
                 $this->assertContains('fade-from-center', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_NEWSFLASH':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PLUS':
                 $this->assertContains('close', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PULL_DOWN':
                 $this->assertContains('stretch-from-bottom', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PULL_LEFT':
                 $this->assertContains('stretch-from-left', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PULL_RIGHT':
                 $this->assertContains('stretch-from-right', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PULL_UP':
                 $this->assertContains('stretch-from-top', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PUSH_DOWN':
                 $this->assertContains('roll-from-bottom', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PUSH_LEFT':
                 $this->assertContains('roll-from-left', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PUSH_RIGHT':
                 $this->assertContains('roll-from-right', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_PUSH_UP':
                 $this->assertContains('roll-from-top', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_RANDOM':
                 $this->assertContains('random', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_RANDOMBAR_HORIZONTAL':
                 $this->assertContains('horizontal-lines', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_RANDOMBAR_VERTICAL':
                 $this->assertContains('vertical-lines', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_SPLIT_IN_HORIZONTAL':
                 $this->assertContains('close-horizontal', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_SPLIT_OUT_HORIZONTAL':
                 $this->assertContains('open-horizontal', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_SPLIT_IN_VERTICAL':
                 $this->assertContains('close-vertical', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_SPLIT_OUT_VERTICAL':
                 $this->assertContains('open-vertical', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_STRIPS_LEFT_DOWN':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_STRIPS_LEFT_UP':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_STRIPS_RIGHT_DOWN':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_STRIPS_RIGHT_UP':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_WEDGE':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_WIPE_DOWN':
                 $this->assertContains('fade-from-bottom', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_WIPE_LEFT':
                 $this->assertContains('fade-from-left', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_WIPE_RIGHT':
                 $this->assertContains('fade-from-right', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_WIPE_UP':
                 $this->assertContains('fade-from-top', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_ZOOM_IN':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
             case 'TRANSITION_ZOOM_OUT':
                 $this->assertContains('none', $pres->getElementAttribute($element, 'presentation:transition-style', 'content.xml'));
                 break;
         }
     }
     $oTransition->setManualTrigger(true);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $this->assertContains('manual', $pres->getElementAttribute($element, 'presentation:transition-type', 'content.xml'));
 }
Esempio n. 22
0
 /**
  * Write content 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-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');
     $shapeId = 0;
     foreach ($pPHPPowerPoint->getAllSlides() as $pSlide) {
         // Images
         $shapes = $pSlide->getShapeCollection();
         foreach ($shapes as $shape) {
             // Increment $shapeId
             ++$shapeId;
             // Check type
             if ($shape instanceof 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');
                 if (is_bool($shape->hasAutoShrinkVertical())) {
                     $objWriter->writeAttribute('draw:auto-grow-height', var_export($shape->hasAutoShrinkVertical(), true));
                 }
                 if (is_bool($shape->hasAutoShrinkHorizontal())) {
                     $objWriter->writeAttribute('draw:auto-grow-width', var_export($shape->hasAutoShrinkHorizontal(), true));
                 }
                 switch ($shape->getFill()->getFillType()) {
                     case Fill::FILL_NONE:
                     default:
                         $objWriter->writeAttribute('draw:fill', 'none');
                         $objWriter->writeAttribute('draw:fill-color', '#' . $shape->getFill()->getStartColor()->getRGB());
                         break;
                 }
                 switch ($shape->getBorder()->getLineStyle()) {
                     case Border::LINE_NONE:
                     default:
                         $objWriter->writeAttribute('draw:stroke', 'none');
                         $objWriter->writeAttribute('svg:stroke-color', '#' . $shape->getBorder()->getColor()->getRGB());
                 }
                 $objWriter->writeAttribute('fo:wrap-option', 'wrap');
                 // > style:graphic-properties
                 $objWriter->endElement();
                 // > style:style
                 $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 Run) {
                             // Style des font text
                             if (!isset($arrStyleTextFont[$richtext->getFont()->getHashCode()])) {
                                 $arrStyleTextFont[$richtext->getFont()->getHashCode()] = $richtext->getFont();
                             }
                         }
                     }
                 }
             }
             if ($shape instanceof AbstractDrawing) {
                 if ($shape->getShadow()->isVisible()) {
                     // 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', SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
                     } elseif ($shape->getShadow()->getDirection() == 45) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 90) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 135) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 180) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
                     } elseif ($shape->getShadow()->getDirection() == 225) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '-' . SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 270) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     } elseif ($shape->getShadow()->getDirection() == 315) {
                         $objWriter->writeAttribute('draw:shadow-offset-x', SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                         $objWriter->writeAttribute('draw:shadow-offset-y', '-' . SharedDrawing::pixelsToCentimeters($shape->getShadow()->getDistance()) . 'cm');
                     }
                     $objWriter->writeAttribute('draw:shadow-opacity', 100 - $shape->getShadow()->getAlpha() . '%');
                     $objWriter->writeAttribute('style:mirror', 'none');
                     $objWriter->endElement();
                     $objWriter->endElement();
                 }
             }
             if ($shape instanceof Line) {
                 // 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:fill', 'none');
                 switch ($shape->getBorder()->getLineStyle()) {
                     case Border::LINE_NONE:
                         $objWriter->writeAttribute('draw:stroke', 'none');
                         break;
                     case Border::LINE_SINGLE:
                         $objWriter->writeAttribute('draw:stroke', 'solid');
                         break;
                     default:
                         $objWriter->writeAttribute('draw:stroke', 'none');
                         break;
                 }
                 $objWriter->writeAttribute('svg:stroke-color', '#' . $shape->getBorder()->getColor()->getRGB());
                 $objWriter->writeAttribute('svg:stroke-width', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters(SharedDrawing::pointsToPixels($shape->getBorder()->getLineWidth())), 3) . 'cm');
                 $objWriter->endElement();
                 $objWriter->endElement();
             }
             if ($shape instanceof Table) {
                 foreach ($shape->getRows() as $keyRow => $shapeRow) {
                     // style:style
                     $objWriter->startElement('style:style');
                     $objWriter->writeAttribute('style:name', 'gr' . $shapeId . 'r' . $keyRow);
                     $objWriter->writeAttribute('style:family', 'table-row');
                     // style:table-row-properties
                     $objWriter->startElement('style:table-row-properties');
                     $objWriter->writeAttribute('style:row-height', StringHelper::numberFormat(SharedDrawing::pixelsToCentimeters(SharedDrawing::pointsToPixels($shapeRow->getHeight())), 3) . 'cm');
                     $objWriter->endElement();
                     $objWriter->endElement();
                     foreach ($shapeRow->getCells() as $keyCell => $shapeCell) {
                         // style:style
                         $objWriter->startElement('style:style');
                         $objWriter->writeAttribute('style:name', 'gr' . $shapeId . 'r' . $keyRow . 'c' . $keyCell);
                         $objWriter->writeAttribute('style:family', 'table-cell');
                         // style:graphic-properties
                         $objWriter->startElement('style:graphic-properties');
                         if ($shapeCell->getFill()->getFillType() == Fill::FILL_SOLID) {
                             $objWriter->writeAttribute('draw:fill', 'solid');
                             $objWriter->writeAttribute('draw:fill-color', '#' . $shapeCell->getFill()->getStartColor()->getRGB());
                         }
                         if ($shapeCell->getFill()->getFillType() == Fill::FILL_GRADIENT_LINEAR) {
                             $objWriter->writeAttribute('draw:fill', 'gradient');
                             $objWriter->writeAttribute('draw:fill-gradient-name', 'gradient_' . $shapeCell->getFill()->getHashCode());
                         }
                         $objWriter->endElement();
                         // <style:graphic-properties
                         // style:paragraph-properties
                         $objWriter->startElement('style:paragraph-properties');
                         if ($shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getTop()->getHashCode() && $shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getLeft()->getHashCode() && $shapeCell->getBorders()->getBottom()->getHashCode() == $shapeCell->getBorders()->getRight()->getHashCode()) {
                             $lineStyle = 'none';
                             $lineWidth = StringHelper::numberFormat($shapeCell->getBorders()->getBottom()->getLineWidth() / 1.75, 2);
                             $lineColor = $shapeCell->getBorders()->getBottom()->getColor()->getRGB();
                             switch ($shapeCell->getBorders()->getBottom()->getLineStyle()) {
                                 case Border::LINE_SINGLE:
                                     $lineStyle = 'solid';
                             }
                             $objWriter->writeAttribute('fo:border', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                         } else {
                             $lineStyle = 'none';
                             $lineWidth = StringHelper::numberFormat($shapeCell->getBorders()->getBottom()->getLineWidth() / 1.75, 2);
                             $lineColor = $shapeCell->getBorders()->getBottom()->getColor()->getRGB();
                             switch ($shapeCell->getBorders()->getBottom()->getLineStyle()) {
                                 case Border::LINE_SINGLE:
                                     $lineStyle = 'solid';
                             }
                             $objWriter->writeAttribute('fo:border-bottom', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                             // TOP
                             $lineStyle = 'none';
                             $lineWidth = StringHelper::numberFormat($shapeCell->getBorders()->getTop()->getLineWidth() / 1.75, 2);
                             $lineColor = $shapeCell->getBorders()->getTop()->getColor()->getRGB();
                             switch ($shapeCell->getBorders()->getTop()->getLineStyle()) {
                                 case Border::LINE_SINGLE:
                                     $lineStyle = 'solid';
                             }
                             $objWriter->writeAttribute('fo:border-top', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                             // RIGHT
                             $lineStyle = 'none';
                             $lineWidth = StringHelper::numberFormat($shapeCell->getBorders()->getRight()->getLineWidth() / 1.75, 2);
                             $lineColor = $shapeCell->getBorders()->getRight()->getColor()->getRGB();
                             switch ($shapeCell->getBorders()->getRight()->getLineStyle()) {
                                 case Border::LINE_SINGLE:
                                     $lineStyle = 'solid';
                             }
                             $objWriter->writeAttribute('fo:border-right', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                             // LEFT
                             $lineStyle = 'none';
                             $lineWidth = StringHelper::numberFormat($shapeCell->getBorders()->getLeft()->getLineWidth() / 1.75, 2);
                             $lineColor = $shapeCell->getBorders()->getLeft()->getColor()->getRGB();
                             switch ($shapeCell->getBorders()->getLeft()->getLineStyle()) {
                                 case Border::LINE_SINGLE:
                                     $lineStyle = 'solid';
                             }
                             $objWriter->writeAttribute('fo:border-left', $lineWidth . 'pt ' . $lineStyle . ' #' . $lineColor);
                         }
                         $objWriter->endElement();
                         $objWriter->endElement();
                         foreach ($shapeCell->getParagraphs() as $shapeParagraph) {
                             foreach ($shapeParagraph->getRichTextElements() as $shapeRichText) {
                                 if ($shapeRichText instanceof Run) {
                                     // Style des font text
                                     if (!isset($arrStyleTextFont[$shapeRichText->getFont()->getHashCode()])) {
                                         $arrStyleTextFont[$shapeRichText->getFont()->getHashCode()] = $shapeRichText->getFont();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // 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', SharedDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - -1 * $oAlign->getIndent()) . 'cm');
                         $objWriter->writeAttribute('text:min-label-width', SharedDrawing::pixelsToCentimeters(-1 * $oAlign->getIndent()) . 'cm');
                     } else {
                         $objWriter->writeAttribute('text:space-before', SharedDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - $oAlign->getIndent()) . 'cm');
                         $objWriter->writeAttribute('text:min-label-width', SharedDrawing::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 Alignment::HORIZONTAL_LEFT:
                     $objWriter->writeAttribute('fo:text-align', 'left');
                     break;
                 case Alignment::HORIZONTAL_RIGHT:
                     $objWriter->writeAttribute('fo:text-align', 'right');
                     break;
                 case Alignment::HORIZONTAL_CENTER:
                     $objWriter->writeAttribute('fo:text-align', 'center');
                     break;
                 case Alignment::HORIZONTAL_JUSTIFY:
                     $objWriter->writeAttribute('fo:text-align', 'justify');
                     break;
                 case Alignment::HORIZONTAL_DISTRIBUTED:
                     $objWriter->writeAttribute('fo:text-align', 'justify');
                     break;
                 default:
                     $objWriter->writeAttribute('fo:text-align', 'left');
                     break;
             }
             $objWriter->endElement();
             $objWriter->endElement();
         }
     }
     // Style : Text : Font
     if (!empty($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->isBold()) {
                 $objWriter->writeAttribute('fo:font-weight', 'bold');
             }
             // @todo : style:text-underline-style
             $objWriter->endElement();
             $objWriter->endElement();
         }
     }
     $objWriter->endElement();
     //===============================================
     // Body
     //===============================================
     // office:body
     $objWriter->startElement('office:body');
     // office:presentation
     $objWriter->startElement('office:presentation');
     // Write slides
     $slideCount = $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 RichText) {
                 $this->writeShapeTxt($objWriter, $shape, $shapeId);
             } elseif ($shape instanceof Table) {
                 $this->writeShapeTable($objWriter, $shape, $shapeId);
             } elseif ($shape instanceof Line) {
                 $this->writeShapeLine($objWriter, $shape, $shapeId);
             } elseif ($shape instanceof Chart) {
                 $this->writeShapeChart($objWriter, $shape, $shapeId);
             } elseif ($shape instanceof AbstractDrawing) {
                 $this->writeShapePic($objWriter, $shape, $shapeId);
             }
         }
         $objWriter->endElement();
     }
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }
Esempio n. 23
0
 /**
  * Write slides
  *
  * @param  \PhpOffice\Common\XMLWriter $objWriter       XML Writer
  * @param  PhpPowerpoint                  $pPHPPowerPoint
  * @param  int                            $startRelationId
  * @throws \Exception
  */
 private function writeSlides(XMLWriter $objWriter, PhpPowerpoint $pPHPPowerPoint, $startRelationId = 2)
 {
     // Write slides
     $slideCount = $pPHPPowerPoint->getSlideCount();
     for ($i = 0; $i < $slideCount; ++$i) {
         // p:sldId
         $this->writeSlide($objWriter, $i + 256, $i + $startRelationId);
     }
 }
    echo date('H:i:s') . ' Create templated slide' . EOL;
    $currentSlide = createTemplatedSlide($objPHPPowerPoint);
    // Create a shape (text)
    echo date('H:i:s') . ' Create a shape (rich text) with shadow' . EOL;
    $shape = $currentSlide->createRichTextShape();
    $shape->setHeight(100);
    $shape->setWidth(400);
    $shape->setOffsetX(100);
    $shape->setOffsetY(100);
    $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
    $shape->getShadow()->setVisible(true)->setAlpha(75)->setBlurRadius(2)->setDirection(45);
    $textRun = $shape->createTextRun('RichText with shadow');
    $textRun->getFont()->setColor(new Color('FF000000'));
}
// 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;
$oProperties = $objPHPPowerPoint->getProperties();
$oProperties->setCreator('PHPOffice')->setLastModifiedBy('PHPPowerPoint Team')->setTitle('Sample 11 Title')->setSubject('Sample 11 Subject')->setDescription('Sample 11 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
// Remove first slide
echo date('H:i:s') . ' Remove first slide' . EOL;
$objPHPPowerPoint->removeSlideByIndex(0);
fnSlideRichText($objPHPPowerPoint);
fnSlideRichTextShadow($objPHPPowerPoint);
// Save file
echo write($objPHPPowerPoint, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}
 public function postFinalpresentation()
 {
     $id_result = Input::get('id_result');
     $resulted = AutomateModel::where('id', $id_result)->first();
     //        $range_name_id = Input::get('range_name_id');
     $result = LogChartModel::where('id_result', $id_result)->get();
     $objPHPPowerPoint = new PhpPowerpoint();
     // Set properties
     //        echo date('H:i:s') . ' Set properties' . EOL;
     $objPHPPowerPoint->getProperties()->setCreator('HAT Developer')->setLastModifiedBy('HAT Developer')->setTitle('Sample 07 Title')->setSubject('Sample 07 Subject')->setDescription('Sample 07 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
     // Remove first slide
     //        echo date('H:i:s') . ' Remove first slide' . EOL;
     $objPHPPowerPoint->removeSlideByIndex(0);
     // Set Style
     $oFill = new Fill();
     //        $oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
     $oShadow = new Shadow();
     $oShadow->setVisible(true)->setDirection(45)->setDistance(10);
     //FIRST SLIDE
     $currentSlide = $this->createTemplatedSlide($objPHPPowerPoint);
     // local function
     // Create a shape (text)
     // Create a shape (text)
     $shape = $currentSlide->createRichTextShape();
     $shape->setHeight(600)->setWidth(930)->setOffsetX(40)->setOffsetY(300);
     $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)->setMarginLeft(25)->setIndent(-25);
     $shape->getActiveParagraph()->getFont()->setSize(18)->setColor(new Color('E07116'));
     //        $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
     $shape->createTextRun($resulted->info);
     //END OF FIRST SLIDE
     $index = 0;
     //        print_r('here'); exit();
     foreach ($result as $file) {
         //            echo $file->filename.'<br>';
         $currentSlide = $this->createTemplatedSlide($objPHPPowerPoint);
         $shape = $currentSlide->createDrawingShape();
         $shape->setName('Result Chart')->setDescription('PHPPowerPoint logo')->setPath(public_path($file->filename))->setHeight(450)->setWidth(650)->setOffsetX(100)->setOffsetY(160);
         $shape->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
         $shape = $currentSlide->createRichTextShape();
         $shape->setHeight(50)->setWidth(930)->setOffsetX(20)->setOffsetY(45);
         $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setMarginLeft(25)->setIndent(-25);
         $shape->getActiveParagraph()->getFont()->setSize(23)->setColor(new Color('D66204'));
         //        $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
         $title = explode(',', $file->title);
         $plot_data = PlotDataModel::where('id_plot', $file->id_plot)->get();
         $plot_name = PlotModel::where('id', $file->id_plot)->first();
         $technya = TechnologyModel::where('id', $plot_name->id_tech)->first();
         if ($technya->name == 'UMTS') {
             $shape->createTextRun(str_ireplace('ch', 'UARFCN', $title[1]) . ' Histogram');
         } else {
             if ($technya->name == 'LTE') {
                 $shape->createTextRun(str_ireplace('ch', 'LARFCN', $title[1]) . ' Histogram');
             } else {
                 $shape->createTextRun(str_ireplace('ch', 'ARFCN', $title[1]) . ' Histogram');
             }
         }
         $co = count($plot_data);
         $shape = $currentSlide->createTableShape(1);
         $shape->setWidth(150);
         $shape->setOffsetX(760);
         $shape->setOffsetY(200);
         $row = $shape->createRow();
         $row->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('EEF0EB'))->setEndColor(new Color('EEF0EB'));
         $row->nextCell()->createTextRun($plot_name->name);
         $i = 2;
         foreach ($plot_data as $rw) {
             $row = $shape->createRow();
             if ($i % 2 == 0) {
                 $row->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('DCEBCA'))->setEndColor(new Color('DCEBCA'));
             } else {
                 $row->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('EEF0EB'))->setEndColor(new Color('EEF0EB'));
             }
             $row->nextCell()->createTextRun($rw->start . ' to ' . $rw->end);
             $i++;
         }
         $index++;
     }
     // Save file
     $named = date('Ymdhis_') . $this->toAscii($resulted->info);
     $this->write($objPHPPowerPoint, $named, $this->writers);
     $resultsave = AutomateModel::find($id_result);
     $resultsave->file_result = date('Y-m-d') . '/' . $named;
     $resultsave->save();
     Session::flash('message', SiteHelpers::alert('success', Lang::get('Process has completed, check the result on table bellow')));
     return Redirect::to('/automate');
 }
 /**
  * Creates a templated slide
  *
  * @param PHPPowerPoint $objPHPPowerPoint
  * @return PHPPowerPoint_Slide
  */
 function createTemplatedSlide(PhpOffice\PhpPowerpoint\PhpPowerpoint $objPHPPowerPoint)
 {
     // Create slide
     $slide = $objPHPPowerPoint->createSlide();
     // Add logo
     $shape = $slide->createDrawingShape();
     $shape->setName('PHPPowerPoint logo')->setDescription('PHPPowerPoint logo')->setPath(public_path('resources/logo_right_alpha.png'))->setHeight(18)->setOffsetX(680)->setOffsetY(10);
     $shape->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
     $shape_2 = $slide->createRichTextShape()->setHeight(50)->setWidth(500)->setOffsetX(70)->setOffsetY(660)->setInsetTop(5)->setInsetBottom(5);
     $shape_2->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
     $textRun = $shape_2->createTextRun('© 2015 AT&T Intellectual Property. All rights reserved. AT&T and the AT&T logo are trademarks of AT&T Intellectual Property AT&T Proprietary (Internal Use Only) Not for use or disclosure outside the AT&T companies except under written agreement');
     $textRun->getFont()->setBold(false)->setSize(7)->setColor(new Color('4A4A49'));
     $shape_3 = $slide->createDrawingShape();
     $shape_3->setName('PHPPowerPoint logo')->setDescription('PHPPowerPoint logo')->setPath(public_path('resources/logo_bottom_alpha.png'))->setHeight(40)->setOffsetX(890)->setOffsetY(660);
     $shape_3->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
     // Return slide
     return $slide;
 }
Esempio n. 27
0
 public function testTransition()
 {
     $value = rand(1000, 5000);
     $oTransition = new Transition();
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $element = '/p:sld/p:transition';
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
     $this->assertFalse($pres->elementExists($element, 'ppt/slides/slide1.xml'));
     $oTransition->setTimeTrigger(true, $value);
     $oSlide->setTransition($oTransition);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
     $this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
     $this->assertTrue($pres->attributeElementExists($element, 'advTm', 'ppt/slides/slide1.xml'));
     $this->assertEquals($value, $pres->getElementAttribute($element, 'advTm', 'ppt/slides/slide1.xml'));
     $this->assertContains('0', $pres->getElementAttribute($element, 'advClick', 'ppt/slides/slide1.xml'));
     $oTransition->setSpeed(Transition::SPEED_FAST);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
     $this->assertContains('fast', $pres->getElementAttribute($element, 'spd', 'ppt/slides/slide1.xml'));
     $oTransition->setSpeed(Transition::SPEED_MEDIUM);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
     $this->assertContains('med', $pres->getElementAttribute($element, 'spd', 'ppt/slides/slide1.xml'));
     $oTransition->setSpeed(Transition::SPEED_SLOW);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
     $this->assertContains('slow', $pres->getElementAttribute($element, 'spd', 'ppt/slides/slide1.xml'));
     $rcTransition = new \ReflectionClass('PhpOffice\\PhpPowerpoint\\Slide\\Transition');
     $arrayConstants = $rcTransition->getConstants();
     foreach ($arrayConstants as $key => $value) {
         if (strpos($key, 'TRANSITION_') !== 0) {
             continue;
         }
         $oTransition->setTransitionType($rcTransition->getConstant($key));
         $oSlide->setTransition($oTransition);
         $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
         switch ($key) {
             case 'TRANSITION_BLINDS_HORIZONTAL':
                 $this->assertTrue($pres->elementExists($element . '/p:blinds[@dir=\'horz\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_BLINDS_VERTICAL':
                 $this->assertTrue($pres->elementExists($element . '/p:blinds[@dir=\'vert\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_CHECKER_HORIZONTAL':
                 $this->assertTrue($pres->elementExists($element . '/p:checker[@dir=\'horz\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_CHECKER_VERTICAL':
                 $this->assertTrue($pres->elementExists($element . '/p:checker[@dir=\'vert\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_CIRCLE_HORIZONTAL':
                 $this->assertTrue($pres->elementExists($element . '/p:circle[@dir=\'horz\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_CIRCLE_VERTICAL':
                 $this->assertTrue($pres->elementExists($element . '/p:circle[@dir=\'vert\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COMB_HORIZONTAL':
                 $this->assertTrue($pres->elementExists($element . '/p:comb[@dir=\'horz\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COMB_VERTICAL':
                 $this->assertTrue($pres->elementExists($element . '/p:comb[@dir=\'vert\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'d\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_LEFT':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'l\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_LEFT_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'ld\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_LEFT_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'lu\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_RIGHT':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'r\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_RIGHT_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'rd\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_RIGHT_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'ru\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_COVER_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:cover[@dir=\'u\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_CUT':
                 $this->assertTrue($pres->elementExists($element . '/p:cut', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_DIAMOND':
                 $this->assertTrue($pres->elementExists($element . '/p:diamond', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_DISSOLVE':
                 $this->assertTrue($pres->elementExists($element . '/p:dissolve', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_FADE':
                 $this->assertTrue($pres->elementExists($element . '/p:fade', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_NEWSFLASH':
                 $this->assertTrue($pres->elementExists($element . '/p:newsflash', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PLUS':
                 $this->assertTrue($pres->elementExists($element . '/p:plus', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PULL_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:pull[@dir=\'d\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PULL_LEFT':
                 $this->assertTrue($pres->elementExists($element . '/p:pull[@dir=\'l\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PULL_RIGHT':
                 $this->assertTrue($pres->elementExists($element . '/p:pull[@dir=\'r\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PULL_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:pull[@dir=\'u\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PUSH_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:push[@dir=\'d\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PUSH_LEFT':
                 $this->assertTrue($pres->elementExists($element . '/p:push[@dir=\'l\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PUSH_RIGHT':
                 $this->assertTrue($pres->elementExists($element . '/p:push[@dir=\'r\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_PUSH_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:push[@dir=\'u\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_RANDOM':
                 $this->assertTrue($pres->elementExists($element . '/p:random', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_RANDOMBAR_HORIZONTAL':
                 $this->assertTrue($pres->elementExists($element . '/p:randomBar[@dir=\'horz\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_RANDOMBAR_VERTICAL':
                 $this->assertTrue($pres->elementExists($element . '/p:randomBar[@dir=\'vert\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_SPLIT_IN_HORIZONTAL':
                 $this->assertTrue($pres->elementExists($element . '/p:split[@dir=\'in\'][@orient=\'horz\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_SPLIT_OUT_HORIZONTAL':
                 $this->assertTrue($pres->elementExists($element . '/p:split[@dir=\'out\'][@orient=\'horz\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_SPLIT_IN_VERTICAL':
                 $this->assertTrue($pres->elementExists($element . '/p:split[@dir=\'in\'][@orient=\'vert\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_SPLIT_OUT_VERTICAL':
                 $this->assertTrue($pres->elementExists($element . '/p:split[@dir=\'out\'][@orient=\'vert\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_STRIPS_LEFT_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:strips[@dir=\'ld\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_STRIPS_LEFT_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:strips[@dir=\'lu\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_STRIPS_RIGHT_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:strips[@dir=\'rd\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_STRIPS_RIGHT_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:strips[@dir=\'ru\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_WEDGE':
                 $this->assertTrue($pres->elementExists($element . '/p:wedge', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_WIPE_DOWN':
                 $this->assertTrue($pres->elementExists($element . '/p:wipe[@dir=\'d\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_WIPE_LEFT':
                 $this->assertTrue($pres->elementExists($element . '/p:wipe[@dir=\'l\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_WIPE_RIGHT':
                 $this->assertTrue($pres->elementExists($element . '/p:wipe[@dir=\'r\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_WIPE_UP':
                 $this->assertTrue($pres->elementExists($element . '/p:wipe[@dir=\'u\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_ZOOM_IN':
                 $this->assertTrue($pres->elementExists($element . '/p:zoom[@dir=\'in\']', 'ppt/slides/slide1.xml'));
                 break;
             case 'TRANSITION_ZOOM_OUT':
                 $this->assertTrue($pres->elementExists($element . '/p:zoom[@dir=\'out\']', 'ppt/slides/slide1.xml'));
                 break;
         }
     }
     $oTransition->setManualTrigger(true);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'PowerPoint2007');
     $this->assertContains('1', $pres->getElementAttribute($element, 'advClick', 'ppt/slides/slide1.xml'));
 }
include_once 'Sample_Header.php';
use PhpOffice\PhpPowerpoint\PhpPowerpoint;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Bar3D;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Line;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Pie3D;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Scatter;
use PhpOffice\PhpPowerpoint\Shape\Chart\Series;
use PhpOffice\PhpPowerpoint\Style\Alignment;
use PhpOffice\PhpPowerpoint\Style\Border;
use PhpOffice\PhpPowerpoint\Style\Color;
use PhpOffice\PhpPowerpoint\Style\Fill;
use PhpOffice\PhpPowerpoint\Style\Shadow;
// 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('PHPOffice')->setLastModifiedBy('PHPPowerPoint Team')->setTitle('Sample 07 Title')->setSubject('Sample 07 Subject')->setDescription('Sample 07 Description')->setKeywords('office 2007 openxml libreoffice odt php')->setCategory('Sample Category');
// Remove first slide
echo date('H:i:s') . ' Remove first slide' . EOL;
$objPHPPowerPoint->removeSlideByIndex(0);
// Set Style
$oFill = new Fill();
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));
$oShadow = new Shadow();
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);
// Generate sample data for chart
echo date('H:i:s') . ' Generate sample data for chart' . EOL;
$seriesData = array('Monday' => 12, 'Tuesday' => 15, 'Wednesday' => 13, 'Thursday' => 17, 'Friday' => 14, 'Saturday' => 9, 'Sunday' => 7);
// Create templated slide
Esempio n. 29
0
 public function testTypeScatterSuperScript()
 {
     $seriesData = array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2);
     $oPHPPowerPoint = new PhpPowerpoint();
     $oSlide = $oPHPPowerPoint->getActiveSlide();
     $oShape = $oSlide->createChartShape();
     $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80);
     $oScatter = new Scatter();
     $oSeries = new Series('Downloads', $seriesData);
     $oSeries->getFont()->setSuperScript(true);
     $oScatter->addSeries($oSeries);
     $oShape->getPlotArea()->setType($oScatter);
     $oXMLDoc = TestHelperDOCX::getDocument($oPHPPowerPoint, 'PowerPoint2007');
     $element = '/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:dLbls/c:txPr/a:p/a:pPr/a:defRPr';
     $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename()));
     $this->assertEquals('30000', $oXMLDoc->getElementAttribute($element, 'baseline', 'ppt/charts/' . $oShape->getIndexedFilename()));
 }
Esempio n. 30
0
 public function testTableWithText()
 {
     $oRun = new Run();
     $oRun->setText('Test');
     $phpPowerPoint = new PhpPowerpoint();
     $oSlide = $phpPowerPoint->getActiveSlide();
     $oShape = $oSlide->createTableShape();
     $oRow = $oShape->createRow();
     $oCell = $oRow->getCell();
     $oCell->addText($oRun);
     $pres = TestHelperDOCX::getDocument($phpPowerPoint, 'ODPresentation');
     $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/table:table/table:table-row/table:table-cell/text:p/text:span';
     $this->assertTrue($pres->elementExists($element, 'content.xml'));
     $this->assertEquals('Test', $pres->getElement($element, 'content.xml')->nodeValue);
 }