Description
I'm having an issue where I'm attempting to load an existing PPTX file, with a background fill colour, defined as an "Area" in LibreOffice Impress, or as a solidFill in the slide XML.
All background fill colours, or "Area" shapes, appear to be completely discarded by IOFactory's load function.
I thought it was just me, so I modified Sample_06_Fill.php to attempt to reload, then resave the PPTX file it just generated, adding the following block of code just before the Sample_Footer:
$oReaderPPTX = IOFactory::createReader('PowerPoint2007');
$phpPowerpoint = $oReaderPPTX->load('results/Sample_06_Fill.pptx');
$oWriterPPTX = IOFactory::createWriter($phpPowerpoint, 'PowerPoint2007');
$oWriterPPTX->save("results/Sample_06_Fill_Reload.pptx");
The resultant PPTX file has all its background colours stripped out.
I've done tests with very simple PPTX files, where there's a single area of colour on the page and nothing else, and the slide's shape collection is entirely empty.
Does the load function discard areas?
<?php
include_once 'Sample_Header.php';
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Fill;
use PhpOffice\PhpPresentation\IOFactory;
// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();
// Set properties
echo date('H:i:s') . ' Set properties'.EOL;
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPresentation 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 = $objPHPPresentation->getActiveSlide();
for($inc = 1 ; $inc <= 4 ; $inc++){
// Create a shape (text)
echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
$shape = $currentSlide->createRichTextShape()
->setHeight(200)
->setWidth(300);
if($inc == 1 || $inc == 3){
$shape->setOffsetX(10);
} else {
$shape->setOffsetX(320);
}
if($inc == 1 || $inc == 2){
$shape->setOffsetY(10);
} else {
$shape->setOffsetY(220);
}
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
switch ($inc) {
case 1 :
$shape->getFill()->setFillType(Fill::FILL_NONE);
break;
case 2 :
$shape->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)->setRotation(90)->setStartColor(new Color( 'FF4672A8' ))->setEndColor(new Color( 'FF000000' ));
break;
case 3 :
$shape->getFill()->setFillType(Fill::FILL_GRADIENT_PATH)->setRotation(90)->setStartColor(new Color( 'FF4672A8' ))->setEndColor(new Color( 'FF000000' ));
break;
case 4 :
$shape->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color( 'FF4672A8' ))->setEndColor(new Color( 'FF4672A8' ));
break;
}
$textRun = $shape->createTextRun('Use PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(30)
->setColor( new Color('FFE06B20') );
}
$oReaderPPTX = IOFactory::createReader('PowerPoint2007');
$phpPowerpoint = $oReaderPPTX->load('results/Sample_06_Fill.pptx');
$oWriterPPTX = IOFactory::createWriter($phpPowerpoint, 'PowerPoint2007');
$oWriterPPTX->save("results/Sample_06_Fill_Reload.pptx");
// Save file
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}
SampleArea's Slide XML:
<p:sp> <p:nvSpPr> <p:cNvPr id="82" name="CustomShape 1"></p:cNvPr> <p:cNvSpPr/> <p:nvPr/> </p:nvSpPr> <p:spPr> <a:xfrm> <a:off x="0" y="0"/> <a:ext cx="9143640" cy="3456000"/> </a:xfrm> <a:prstGeom prst="rect"> <a:avLst></a:avLst> </a:prstGeom> <a:solidFill> <a:srgbClr val="ff0000"/> </a:solidFill> <a:ln> <a:noFill/> </a:ln> </p:spPr> <p:style> <a:lnRef idx="2"> <a:schemeClr val="accent1"> <a:shade val="50000"/> </a:schemeClr> </a:lnRef> <a:fillRef idx="1"> <a:schemeClr val="accent1"/> </a:fillRef> <a:effectRef idx="0"> <a:schemeClr val="accent1"/> </a:effectRef> <a:fontRef idx="minor"/> </p:style> </p:sp>