Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tusharsharma144 opened this issue Nov 26, 2020 · 3 comments · Fixed by #2506
Closed

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

Tusharsharma144 opened this issue Nov 26, 2020 · 3 comments · Fixed by #2506
Milestone

Comments

@Tusharsharma144
Copy link

Tusharsharma144 commented Nov 26, 2020

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

  • PHP Version: 7.4
  • PHPWord Version: 0.17.0
@dwiyudirayia
Copy link

Is it bug still exists?

@Aless55
Copy link

Aless55 commented Nov 26, 2021

Yes this Bug still exists..

@filippotoso
Copy link
Contributor

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants