Forum


Replies: 1   Views: 245
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.

 

Posted by admin  · 25-01-2024 - 11:49

Hello,

Please check and run the samples included in examples/FormatConversion/transformDocument/msword. Please note the following information detailed in these samples:

// global paths must be used
$docx->transformDocument('C:\\path\\transformDocument_msword_1.docx', 'C:\\path\\transformDocument_msword_1.pdf', 'msword');

Global paths must be used to set source and target files (aso please note double backslashes ('\\') must be used for each directory). You can read about these same requirements on https://www.phpdocx.com/documentation/conversion-plugin/common-problems-and-possible-errors (MS Word common problems and issues section):

Source and target files must use absolute paths and double backslashes: 'C:\\folder\\source.docx' .

We recommend you test the included samples (after changing path to the correct global path to your files) using PHP CLI to check if PHP COM is working correctly.

Also please note that using a Windows server you can use all conversion plugins.

Regards.