Thursday, 3 September 2020

Style & layout is not copied while creating new pptx from pptx in PHPPresentation

I want to split slides of one pptx file into seperated pptx files, containing one slide each. The content/text is copied but the layout & styling is not copied. Here is the code.

Can anyone please help ?

<?php 

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory; 
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Slide\SlideLayout;

 $objReader = \PhpOffice\PhpPresentation\IOFactory::createReader('PowerPoint2007');
 $objPHPPowerPoint = $objReader->load('a.pptx');

 $totalSlides = $objPHPPowerPoint->getSlideCount();
 $oMasterSlide = $objPHPPowerPoint->getAllMasterSlides()[0];

 $documentProperties =  $objPHPPowerPoint->getDocumentProperties();

 for ( $count = 0; $count < $totalSlides; $count++ ) {

     $objPHPPresentation = new PhpPresentation();
     $slide = $objPHPPowerPoint->getSlide(  $count );
     $background = $slide->getBackground();

     $newSlide = $objPHPPresentation->addSlide( $slide );
     $newSlide->setBackground ( $background );

     $objPHPPresentation->setAllMasterSlides(  $oMasterSlide );
     $objPHPPresentation->removeSlideByIndex(0);

     $oWriterPPTX = \PhpOffice\PhpPresentation\IOFactory::createWriter($objPHPPresentation, 'PowerPoint2007');
     $oWriterPPTX->save($count.'.pptx');

}


from Style & layout is not copied while creating new pptx from pptx in PHPPresentation

No comments:

Post a Comment