I am trying to convert presentation file to script using php.
PHP Fatal error: Uncaught 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 /home/admin/vba/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php on line 1375 and defined in /home/admin/vba/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php:888 Stack trace: #0 /home/admin/vba/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(1375): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadShapeRichText() #1 /home/admin/vba/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(755): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlideShapes() #2 /home/admin/vba/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(369): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlideNote() #3 /home/admin/vba/vendor/php in /home/admin/vba/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php on line 888
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
// Specify the path to your
// PowerPoint file
$pptxFilePath = '/home/admin/vba/monsoonmalabarpptfin9.pptx';
// Load the PowerPoint file
$presentation = IOFactory::load($pptxFilePath);
// Set the export file path
$exportFilePath = '/home/admin/vba/uu.txt';
// Create a string to store the
// exported content
$exportedContent = "";
// Loop through slides and extract
// information
foreach ($presentation->getAllSlides() as $index => $slide) {
$exportedContent .= "Slide $index:\n"; foreach ($slide->getShapeCollection() as $shape) {
if ($shape->getRichText() !== null) {
$exportedContent .= $shape->getRichText()->getText() . "\n";
}
}
$exportedContent .= "\n";
}
// Write the exported content to a
// text file
file_put_contents($exportFilePath, $exportedContent);
echo "Exported content to $exportFilePath\n";
?>
The error your receiving is a type mismatch, specifically in your case it seems the error may be related to having notes associated with slides, and they are not handled as traditional slides.
To resolve this you can either remove the notes, or revise your script to handle multiple slide types.
Include additional import statements:
Check slide type: