PHPPresentation icon indicating copy to clipboard operation
PHPPresentation copied to clipboard

When updating pptx, it removes texts

Open soth78 opened this issue 2 years ago • 1 comments

Hi!

I'm trying to use this code to open a template pptx, add some images, and write an output text.

The issue I'm seeing is that any texts from the original PPTX are removed. Background stays, style stays, and other images stay as well, but original texts are removed. Could someone help me please?

$filepath = 'includes/template2.pptx';
$outputFilepath = 'data/presentation-' .$id .".pptx";
@unlink($outputFilepath);
$pptReader = IOFactory::createReader('PowerPoint2007');
$presentation = $pptReader->load($filepath);

// INTRODUCTION
$currentSlide = $presentation->getSlide(1);

$shape = $currentSlide->createDrawingShape();
$shape->setName('My Image')
    ->setDescription('This is an example image')
    ->setPath('data/ages_chart-' .$id .'.png')
    ->setHeight(200)
    ->setResizeProportional(true)
    ->setOffsetX(100)
    ->setOffsetY(100);

// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
    ->setHeight(300)
    ->setWidth(600)
    ->setOffsetX(170)
    ->setOffsetY(100);
$shape->getActiveParagraph()->getAlignment()
    ->setHorizontal(Alignment::HORIZONTAL_CENTER);
$shape->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE));
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
    ->setSize(60)
    ->setColor(new Color(Color::COLOR_WHITE));

// EXPOSURE
$currentSlide = $presentation->getSlide(1);

$shape = $currentSlide->createDrawingShape();
$shape->setName('Exposure Graph')
    ->setDescription('Graph with stolen credentials over time')
    ->setPath('data/infection_chart-' .$id .'.png')
    ->setWidth(900)
    ->setResizeProportional(true)
    ->setOffsetX(10)
    ->setOffsetY(220);

$writer = IOFactory::createWriter($presentation, 'PowerPoint2007');
$writer->save($outputFilepath);

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($outputFilepath) . "\""); 
readfile($outputFilepath); 

soth78 avatar Feb 20 '23 09:02 soth78

@soth78 Hi, Could you send me a sample file with error, please, for reproducing the bug ?

Progi1984 avatar Aug 21 '24 21:08 Progi1984