Forum


Replies: 2   Views: 2269
Bug with transformsizes and non-numeric values
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 helpdesk@hrdownloads.com  · 14-02-2019 - 21:00

I'm getting a critical error converting a docx document. The error appears to be related to the transformSizes function and occurs in the main transform function when processing the document xml. Other docx files process normally.

I dug into the XML code and found a number of elements that were set to "nil". I'm not certain that this is the source of the issue but I can see this causing potential problems if nil isn't converting to zero.

<w:top w:val="nil"/>

[2019-02-14 19:52:32] development.ERROR: A non-numeric value encountered {"exception":"[object] (ErrorException(code: 0): A non-numeric value encountered at /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTMLDefaultPlugin.php:126)
[stacktrace]
#0 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTMLDefaultPlugin.php(126): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'A non-numeric v...', '/home/local.user...', 126, Array)
#1 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(832): Phpdocx\\Transform\\TransformDocAdvHTMLDefaultPlugin->transformSizes('', 'eights')
#2 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(2575): Phpdocx\\Transform\\TransformDocAdvHTML->getCellStyles(Object(DOMElement))
#3 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(362): Phpdocx\\Transform\\TransformDocAdvHTML->transformW_TBL(Object(DOMElement), 'docx_5c65c70079...')
#4 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(1298): Phpdocx\\Transform\\TransformDocAdvHTML->transformXml(Object(DOMElement))
#5 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(421): Phpdocx\\Transform\\TransformDocAdvHTML->transformDEFAULT_TAG(Object(DOMElement), 'docx_5c65c6ff18...')
#6 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(1298): Phpdocx\\Transform\\TransformDocAdvHTML->transformXml(Object(DOMElement))
#7 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(421): Phpdocx\\Transform\\TransformDocAdvHTML->transformDEFAULT_TAG(Object(DOMElement), 'docx_5c65c6ff18...')
#8 /home/local.user/project/vendor/project/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvHTML.php(260): Phpdocx\\Transform\\TransformDocAdvHTML->transformXml(Object(DOMDocument))
#9 /home/local.user/project/Modules/Core/Services/DocConversionService.php(82): Phpdocx\\Transform\\TransformDocAdvHTML->transform(Object(Phpdocx\\Transform\\TransformDocAdvHTMLDefaultPlugin))

Posted by admin  · 15-02-2019 - 07:33

Hello,

DOCX to HTML will support nil values in tables in the next release of phpdocx (there's no release date yet).

We recommend you to generate a new class that extends the TransformDocAdvHTMLDefaultPlugin class:

class TransformDocAdvHTMLNewPlugin extends TransformDocAdvHTMLDefaultPlugin

and customize the transformSizes method to handle nil values if needed, for example:

public function transformSizes($value, $source, $target = null)
{
    $returnValue = 0;

    if ($value == 'nil') {
        $value = 0;
    }
...

The transformation classes allow using custom plugins to transform DOCX. For example, if you generate a new class called TransformDocAdvHTMLHRDownloads with the previous change, you can use it without changing the files of the library:

$transformHTMLPlugin = new TransformDocAdvHTMLHRDownloads();

$transform = new Phpdocx\Transform\TransformDocAdvHTML('document.docx');
$html = $transform->transform($transformHTMLPlugin);

You can read more information about extending TransformDocxAdvHTML classes on https://www.phpdocx.com/documentation/introduction/word-to-html-PHP (How to customize transformations section).

Regards.

Posted by helpdesk@hrdownloads.com  · 15-02-2019 - 20:14

Thanks, that did the trick. The instructions were clear, I was able to add this class and process the problem document.