Forum


Replies: 1   Views: 428
Warning: a non-numeric value encountered in *files* while trying to transform docx to pdf
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 TristanCA  · 22-12-2023 - 09:11

hi everyone, i've just started using phpdocx and i'm having some trouble getting everything to work.

i'm on PHP 8.2.11 and i'm using the latest premium version of phpdocx.

So i'm trying to start from a template then replace variables and then create a docx to finally convert it into pdf.

 

here's my code : 

<?php

use Dompdf\Dompdf;

require_once '../Assets/phpdocx/14.5/classes/CreateDocx.php';
require_once '../Assets/phpdocx/14.5/classes/TransformDocAdvNative.php';
require_once '../Assets/DOMPDF/2.0.4/autoload.inc.php';

$V_docx = new CreateDocxFromTemplate('../Tmp/template.docx');
$V_variables = $V_docx->getTemplateVariables();
$V_article = $_POST['article'];
$V_designation = $_POST['designation'];
$V_signature = $_POST['signature'];

$V_arrayVariables = array($V_variables['document']['0'] => $V_article, $V_variables['document']['2'] => $V_designation, $V_variables['document']['4'] => $V_signature, $V_variables['document']['6'] => $V_signature);
$V_docx->replaceVariableByText($V_arrayVariables);
if (file_exists('../Tmp/genere/document.docx'))
{
        unlink('../Tmp/genere/document.docx'); // Supprime le fichier existant
}
$V_dompdf = new Dompdf();
$V_options = $V_dompdf->getOptions();
$V_options->setDefaultFont('Courier');
$V_dompdf->setOptions($V_options);
$V_optionsTransform = array(
        'dompdf' => $V_dompdf
);
phpinfo();
$V_docx->createDocx('../Tmp/genere/document');
$V_docx->transformDocument('../Tmp/genere/document.docx', '../Tmp/genere/document.pdf', 'native', $V_optionsTransform);

 i'm using the native method to convert docx to pdf. 

The thing is when i try to execute this code, i get a warning : 

Warning: A non-numeric value encountered in *files*/phpdocx/14.5/classes/TransformDocAdvPDFPlugin.php on line 162

if anyone could enlighten me on what i've misunderstood or done wrong that would be great !

ty for reading

Tristan

 

Posted by admin  · 22-12-2023 - 09:24

Hello,

The native conversion plugin supports a set of contents and styles when transforming DOCX to PDF detailed on https://www.phpdocx.com/documentation/conversion-plugin/preparing-the-templates-for-its-conversion (Supported OOXML tags and attributes when using the native method section).

It seems your template uses some not supported content or style. From the warning you get, maybe some numbering style or format not supported. For this reason a PHP warning appears; also please note that it's not a PHP error, so the conversion shouldn't stop.

If the DOCX includes contents or styles not supported by the native conversion plugin when being transformed to PDF, we recommend you use the conversion plugin based on LibreOffice (https://www.phpdocx.com/documentation/conversion-plugin/information).

If you send to contact[at]phpdocx.com a DOCX sample you are transforming we'll check and send it to the dev team. Each new version of phpdocx supports new contents and styles in the native conversion plugin.

Regards.