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

PowerPoint2007::loadShapeRichText() must be an instance of AbstractSlide, instance of Note given #710

Open Sarke opened 2 years ago

Sarke commented 2 years ago
TypeError: Argument 3 passed to PhpOffice\PhpPresentation\Reader\PowerPoint2007::loadShapeRichText() must be an instance of PhpOffice\PhpPresentation\Slide\AbstractSlide, instance of PhpOffice\PhpPresentation\Slide\Note given, called in /app/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php on line 1387 and defined in /app/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php:886

Stack trace:
#0 /app/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(1387): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadShapeRichText(Object(PhpOffice\Common\XMLReader), Object(DOMElement), Object(PhpOffice\PhpPresentation\Slide\Note))
#1 /app/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(756): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlideShapes(Object(PhpOffice\PhpPresentation\Slide\Note), Object(DOMNodeList), Object(PhpOffice\Common\XMLReader))
#2 /app/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(370): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlideNote('notesSlide1.xml', Object(PhpOffice\PhpPresentation\Slide))
#3 /app/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(170): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlides('<?xml version="...')
#4 /app/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(137): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadFile('/app/data/templ...')
#5 /app/vendor/phpoffice/phppresentation/src/PhpPresentation/IOFactory.php(73): PhpOffice\PhpPresentation\Reader\PowerPoint2007->load('/app/data/templ...')
IvanSerevko commented 2 years ago

vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php

 protected function loadShapeRichText(XMLReader $document, DOMElement $node, AbstractSlide $oSlide): void
 {
        if (!$document->elementExists('p:txBody/a:p/a:r', $node)) {
            return;
        }

replace to

    protected function loadShapeRichText(XMLReader $document, DOMElement $node, $oSlide): void
    {
        if (!$document->elementExists('p:txBody/a:p/a:r', $node) || !$oSlide instanceof AbstractSlide) {
            return;
        }

and in vendor/phpoffice/phppresentation/src/PhpPresentation/Style/Border.php

 public function setLineWidth(int $pValue = 1): self
    {
        $this->lineWidth =  $pValue;

replace to

 public function setLineWidth($pValue = 1): self
    {
        $this->lineWidth = (int) $pValue;

but it is required from the developer

alexfierro commented 1 year ago

I can confirm that @IvanSerevko 's revision fixes this issue quite effectively. Any chance to get this pulled?

s873468834 commented 1 year ago

666666666666666

dmtrbskkv commented 1 year ago

I fork and do this. Mb it's can help: https://github.com/dmtrbskkv/php-presentation-fix

sxaxmz commented 1 year ago

Hi @dmtrbskkv , can you elaborate thanks.

dmtrbskkv commented 1 year ago

Hi @dmtrbskkv , can you elaborate thanks.

I make fork of the main repository and fix this bug. Fix like in this answer. How to install, u can find on repository page

Progi1984 commented 3 months ago

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