Forum


Replies: 4   Views: 1242
Docx supported formats?
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by officiorocks  · 26-01-2021 - 00:55

Hi all,

 

Are there some restrictions/requirements for docx format?

We have one docx file that generates such error:

Argument 1 passed to DOMDocument::importNode() must be an instance of DOMNode, null given at ...\library\PHPDocx\Classes\Phpdocx\Create\CreateDocx.php:917

After the same file was uploaded to Google Docs and downloaded - there is no error.

These files are in a zip here: https://drive.google.com/file/d/1Pd2FBmVCOC8SM6oFn2hW9VzYIBtUrycY/view?usp=sharing

 

The latest 11 version of the PHPDocx is used.

 

Thanks in advance, Andron.

 

Posted by admin  · 26-01-2021 - 06:21

Hello,

How has bad.docx been generated? All DOCX should containt at least one section (w:sectPr tag), but that DOCX doesn't contain any section in the main document file, and also some extra files are missing too in the DOCX.

If you resave it with any DOCX program: MS Word, LibreOffice, Google Docs, a valid DOCX is generated with a section and other files.

Regards.

Posted by officiorocks  · 27-01-2021 - 01:50

Hi,

Thanks for the answer.

 

The docx was downloaded from this service: https://www.learningcontainer.com/sample-docx-file-for-testing/

I understand that I cannot trust that service at all.

 

But is it possible to add some checks in the code so such a fatal error will be not generated?

E.g. a controlled Exception that can be caught above?

 

Thanks, Andron.

Posted by admin  · 27-01-2021 - 08:06

Hello,

phpdocx doesn't throw an Exception in this particular case; a fatal error appears from PHP. All DOCX must contain at least one section (sectPr tag).

An Exception could be added in the class if the following sectPr variable is null:

$sectPr = $sectPrNodes->item(0);

or handle the error in a generic way if you are using PHP 7: https://www.php.net/manual/en/language.errors.php7.php

Using not valid DOCX documents as this case may return unexpected results/errors.

Regards.

Posted by officiorocks  · 27-01-2021 - 22:38

Thanks,

Added such code to skip this error:

try {
    $docx = new CreateDocxFromTemplate($pathToDocx);
} catch (\Throwable $e) {
  // Skipped, do something
}

Works in Php 7+.