PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.23k stars 2.69k forks source link

Not reading/load docx file coming from office 365 #1974

Closed Tusharsharma144 closed 10 months ago

Tusharsharma144 commented 3 years ago

Describe the Bug

I am trying to convert a docx file into pdf which is working fine using other offices but if i use office 365 than it always returning with this bug "trying to get property 'length' of non-object"

Steps to Reproduce

$domPdfPath = base_path('vendor/mpdf/mpdf');
\PhpOffice\PhpWord\Settings::setPdfRendererPath($domPdfPath);
\PhpOffice\PhpWord\Settings::setPdfRendererName('MPDF');
$wordPdf = \PhpOffice\PhpWord\IOFactory::load(storage_path('abc.docx'));
$pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordPdf , 'PDF');
$pdfWriter->save(storage_path('abc.pdf'));

I tried to debug it and looks like when Document.php read function calls $xmlReader->getElements('w:body/*') it is returning empty array on which next lines check for the length of the array any return the error. i have tried with ms office2007 files and ms office2016 which is not returning empty array for the xmlchild but its only happening in office 365

Context

dwiyudirayia commented 2 years ago

Is it bug still exists?

Aless55 commented 2 years ago

Yes this Bug still exists..

filippotoso commented 1 year ago

Hi, I fixed this error adding an ltrim() on row 49 of PhpOffice\PhpWord\Reader\Word2007\Document:

$xmlReader->getDomFromZip($this->docFile, ltrim($this->xmlFile, '/'));