Forum


Replies: 1   Views: 472
Trying to setup the convertion plugin with msword
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  · 25-01-2024 - 11:17

hi everyone, first of all i'm on PHP 8.3.1 and i'm using the latest premium version of phpdocx.

I'm trying to setup phpdocx to simply convert a docx template into a pdf. I choosed the msword method because i'm on a Microsoft Server but i'm having trouble with the convertion. i've setup everything following the documentation, and even try the common errors and mistake for msword but i can't manage to convert a single docx. the check-conversionplugin.php is all green. Here's my code : 

$V_docx = new CreateDocxFromTemplate('./Tmp/templateTableau.docx');
$V_variables = $V_docx->getTemplateVariables();
$V_article = 'ish'; //$_POST['article'];
$V_designation = 'truc'; //$_POST['designation'];
$V_signature = 'osef'; //$_POST['signature'];
$V_nbimpression = 2; //$_POST['nbimpression'];
$V_arrayVariables = array($V_variables['document']['0'] => $V_article, $V_variables['document']['1'] => $V_designation, $V_variables['document']['2'] => $V_signature, $V_variables['document']['3'] => $V_signature);
$V_docx->replaceVariableByText($V_arrayVariables);

if (file_exists('./Tmp/genere/document.docx'))
{
        unlink('./Tmp/genere/document.docx'); // Supprime le fichier existant
}

$V_docx->createDocx('document');

i then tried different thing :

$V_docx->transformDocument('document.docx', 'documentTab.pdf', 'msword', array('selectedContent' => 'active', 'toc' => True));

Fatal error: Uncaught com_exception: Failed to create COM object `word.application': CoInitialize n’a pas été appelé in ...\Assets\phpdocx\14.5\classes\TransformDocAdvMSWord.php:106 Stack trace: #0 ...\Assets\phpdocx\14.5\classes\TransformDocAdvMSWord.php(106): com->__construct() #1 ...\Assets\phpdocx\14.5\classes\CreateDocx.php(9898): TransformDocAdvMSWord->transformDocument() #2 ...\testPDF.php(28): CreateDocx->transformDocument() #3 {main} thrown in ...Assets\phpdocx\14.5\classes\TransformDocAdvMSWord.php on line 106

$V_docx->transformDocument('document.docx', 'documentTab.pdf', 'msword', array('selectedContent' => 'active'));

 

Fatal error: Uncaught com_exception: <b>Source:</b> Microsoft Word<br/><b>Description:</b> Commande non disponible�: aucun document n'est ouvert. in ...\Assets\phpdocx\14.5\classes\TransformDocAdvMSWord.php:134 Stack trace: #0 ...\Assets\phpdocx\14.5\classes\CreateDocx.php(9898): TransformDocAdvMSWord->transformDocument() #1 ...\testPDF.php(19): CreateDocx->transformDocument() #2 {main} thrown in ....Assets\phpdocx\14.5\classes\TransformDocAdvMSWord.php on line 134

 

$V_docx->transformDocument('document.docx', 'documentTab.pdf', 'msword', array('selectedContent' => 'documents'));

 


Fatal error: Uncaught com_exception: <b>Source:</b> Microsoft Word<br/><b>Description:</b> Le membre de la collection requis n'existe pas. in \Assets\phpdocx\14.5\classes\TransformDocAdvMSWord.php:123 Stack trace: #0 \Assets\phpdocx\14.5\classes\CreateDocx.php(9898): TransformDocAdvMSWord->transformDocument() #1 \testPDF.php(19): CreateDocx->transformDocument() #2 {main} thrown in \Assets\phpdocx\14.5\classes\TransformDocAdvMSWord.php on line 123

sorry for the french is the error message, here's the reference for the microsft error in english : 

1- CoInitialize has not been called

2-Run-time error '4248': This command is not available because no document is open.

3- Run-time error '5941': The requested member of the collection does not exist.