PHPOffice / PHPPresentation

A pure PHP library for reading and writing presentations documents
https://phpoffice.github.io/PHPPresentation
Other
1.31k stars 523 forks source link

The file "" doesn't exist #789

Closed nazububu closed 11 months ago

nazububu commented 11 months ago

Hey hey.

Just tried to use package. Installed with composer, copied example, modified. Aaand got exception.

<?php

require_once('vendor/autoload.php');

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

$objPHPPowerPoint = new PhpPresentation();

// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();

// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
    ->setDescription('PHPPresentation logo')
//    ->setPath('./resources/phppowerpoint_logo.gif')
    ->setHeight(36)
    ->setOffsetX(10)
    ->setOffsetY(10);
$shape->getShadow()->setVisible(true)
    ->setDirection(45)
    ->setDistance(10);

// Create a shape (text)
$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 PHPPresentation!');
$textRun->getFont()->setBold(true)
    ->setSize(60)
    ->setColor(new Color('FFE06B20'));

$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(__DIR__ . "/sample.odp");
PHP Fatal error:  Uncaught PhpOffice\PhpPresentation\Exception\FileNotFoundException: The file "" doesn't exist in /srv/dev/vendor/phpoffice/phppresentation/src/PhpPresentation/Shape/Drawing/File.php:77
Stack trace:
#0 /srv/dev/vendor/phpoffice/phppresentation/src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php(133): PhpOffice\PhpPresentation\Shape\Drawing\File->getMimeType()
#1 /srv/dev/vendor/phpoffice/phppresentation/src/PhpPresentation/Writer/PowerPoint2007.php(117): PhpOffice\PhpPresentation\Writer\PowerPoint2007\ContentTypes->render()
#2 /srv/dev/index.php(40): PhpOffice\PhpPresentation\Writer\PowerPoint2007->save()
#3 {main}
  thrown in /srv/dev/vendor/phpoffice/phppresentation/src/PhpPresentation/Shape/Drawing/File.php on line 77

Can you please help with it?

Thanks

nazububu commented 11 months ago

Sorry, I am dumb AF. Path for image missed.