PHPOffice / PHPPresentation

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

Error Loading Files (ppt and pptx) #737

Open sxaxmz opened 1 year ago

sxaxmz commented 1 year ago

Hi, I am trying to use this library to load and convert ppt and pptx files to pdf. Unfortunately, unlike PHPSpredsheet and PHPWord this library is not as rich in options when it comes to writers and options to do that.

I came up with a code to do that alternatively as a workaround but the library is not loading the files, the line that I use to load the file:

$presentation = PresentationIOFactory::load('path_to_file');

Errors that I get when I try to load each file:

PPTX File Load Error:

Fatal error: Uncaught TypeError:PhpOffice\PhpPresentation\Reader\PowerPoint2007::loadShapeRichText(): Argument #3 ($oSlide) must be of type PhpOffice\PhpPresentation\Slide\AbstractSlide, PhpOffice\PhpPresentation\Slide\Note given, called in C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php on line 1375 and defined in C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php:888
    Stack trace:
    #0 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php(1375): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadShapeRichText(Object(PhpOffice\Common\XMLReader), Object(DOMElement), Object(PhpOffice\PhpPresentation\Slide\Note))
    #1 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php(755): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlideShapes(Object(PhpOffice\PhpPresentation\Slide\Note), Object(DOMNodeList), Object(PhpOffice\Common\XMLReader))
    #2 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php(369): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlideNote('notesSlide1.xml', Object(PhpOffice\PhpPresentation\Slide))
    #3 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php(169): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlides('<?xml version="...')
    #4 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php(136): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadFile('C:/xampp/htdocs...')
    #5 C:\xampp\htdocs\a\create_thumbnail.php(70): PhpOffice\PhpPresentation\Reader\PowerPoint2007->load('C:/xampp/htdocs...')
    #6 C:\xampp\htdocs\a\create_thumbnail.php(142): getThumbnail('../uploads/pptx...', 'Results Discuss...', 'C:/xampp/htdocs...', '../uploads/tmp/', 'pptx', '126', Object(mysqli))
    #7 {main}
      thrown in C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint2007.php on line 888

PPT File Load Error:

Fatal error: Uncaught TypeError: 

PhpOffice\Common\Microsoft\OLERead::getStream(): Argument #1 ($stream) must be of type int, null given, called in C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint97.php on line 487 and defined in C:\xampp\htdocs\vendor\phpoffice\common\src\Common\Microsoft\OLERead.php:203
    Stack trace:
    #0 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint97.php(487): PhpOffice\Common\Microsoft\OLERead->getStream(NULL)
    #1 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint97.php(454): PhpOffice\PhpPresentation\Reader\PowerPoint97->loadOLE()
    #2 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Reader\PowerPoint97.php(442): PhpOffice\PhpPresentation\Reader\PowerPoint97->loadFile()
    #3 C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\IOFactory.php(73): PhpOffice\PhpPresentation\Reader\PowerPoint97->load('C:/xampp/htdocs...')
    #4 C:\xampp\htdocs\a\create_thumbnail.php(112): PhpOffice\PhpPresentation\IOFactory::load('C:/xampp/htdocs...')
    #5 C:\xampp\htdocs\a\create_thumbnail.php(177): getThumbnail('../uploads/ppt/...', 'Architecture_xx...', 'C:/xampp/htdocs...', '../uploads/tmp/', 'ppt', '139', Object(mysqli))
    #6 {main}
      thrown in C:\xampp\htdocs\vendor\phpoffice\common\src\Common\Microsoft\OLERead.php on line 203

Stackoverflow link: Convert PPT and PPTX to PDF - PHP

Based on #710 I was able to overcome the issue of load pptx. Still facing issue with loading ppt as per the provided error.

Offbeatmammal commented 1 year ago

@sxaxmz with the fix for #710, were you able to load/save pptx files containing notes (is there another part to the fix that I'm missing?)

Progi1984 commented 3 weeks ago

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