Search code examples
phpphppowerpoint

Unable to change PHPPowerpoint Slide Width and Height


Hi Iam Using PHPpowerpoint Library to generate Power point Presentation via PHP, and I generated Successfully But my problem is the generated PPT's Page Set Up is Width:10 Inches and Height 7.5 Inches. I need to change the Width and Height of Page. where do i change the Width and Height in the Library. Thanks in Advance

<?php
 function createTemplatedSlide(PHPPowerPoint $objPHPPowerPoint){
 // Create slide
 $slide = $objPHPPowerPoint->createSlide();
 // Add background image
 $slide->createDrawingShape()
 ->setName('Background')
 ->setDescription('Background')
 ->setPath('./resources/bg.gif')
 ->setWidth(350)
 ->setHeight(700)
 ->setOffsetX(0)
 ->setOffsetY(0);
 return $slide;
 }


 set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
 include 'PHPPowerPoint.php';
 if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
 define('EOL', PHP_EOL);
 }
 else {
 define('EOL', '<br />');
 }
 $basename="File";
 $objPHPPowerPoint = new PHPPowerPoint();
 $objPHPPowerPoint->getProperties()->setCreator('Monthly Performanace Summary')
                              ->setLastModifiedBy($gLogUserName)
                              ->setTitle('Monthly Performanace Summary')
                              ->setSubject('Monthly Performanace Summary')
                              ->setDescription('Monthly Performanace Summary.')
                              ->setKeywords('Monthly Performanace Summary')
                              ->setCategory('Monthly Performanace Summary');

 $objPHPPowerPoint->removeSlideByIndex(0);
//VF 1 st Slide
$currentSlide = createTemplatedSlide($objPHPPowerPoint); 
 //Slide Content
 $shape = $currentSlide->createDrawingShape();
 $shape->setName('Part page');
 $shape->setDescription('Page');
 $shape->setPath('Sample.jpg'); 
 $shape->setHeight(1300);
 $shape  ->setWidth(1300);
 $shape->getShadow()->setVisible(true);
 $shape->getShadow()->setDirection(15);
 $shape->getShadow()->setDistance(10);
 $formats = array('PowerPoint2007' => 'pptx');
 foreach ($formats as $format => $extension) {
 $objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, $format);
 $FileName="PPT/{$basename}.{$extension}";
 $objWriter->save("PPT/{$basename}.{$extension}");
 }
 ?>

I have added my code and I downloaded Library from https://php-download.com/package/phpoffice/phppowerpoint


Solution

  • Finally I found the Solution in this File "Classes\PHPPowerPoint\Writer\PowerPoint2007\Presentation.php"

    $objWriter->startElement('p:sldSz');
    //$objWriter->writeAttribute('cx', '9144000');
    //$objWriter->writeAttribute('cy', '6858000');
    $objWriter->writeAttribute('cx', $pPHPPowerPoint->getLayout()->getCX());
    $objWriter->writeAttribute('cy', $pPHPPowerPoint->getLayout()->getCY());
    

    Changed the Above Line as

    $objWriter->startElement('p:sldSz');
    $objWriter->writeAttribute('cx', '12190000'); 
    $objWriter->writeAttribute('cy', '6858000');
    // $objWriter->writeAttribute('cx', $pPHPPowerPoint->getLayout()->getCX());
    //$objWriter->writeAttribute('cy', $pPHPPowerPoint->getLayout()->getCY());