Forum


Replies: 11   Views: 364
Transform docx to pdf using ms word with php com closes slow
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 Bertil  · 07-05-2024 - 16:57

Hi, I am struggling with a slow conversion time issue which seems like a timeout exceeded somewhere. 

I want to convert a DOCX to PDF using MSWORD, so I am using the transformDocument method. It works fine, but it takes >30sec. I added logs to see what was taking time in the library, specifically in the TransformDocAdvMSWord.php, whish can be summarised like this : 

// start a Word instance
$MSWordInstance = new COM("word.application");

// open the source document
$MSWordInstance->Documents->Open($source);

// save the target document
$MSWordInstance->ActiveDocument->SaveAs($target, $code[$filesExtensions['targetExtension']]);

// close Word
$MSWordInstance->Quit();

// free memory
$MSWordInstance = null;

And the guilty is the free memory section, that line alone takes 30 sec.

$MSWordInstance = null;

Meanwhile, the PDF has been created almost instantaneously, but I have no response before that 30 sec.

Dunno if linked but I have "COM Surrogate" processes that stay idle even after conversion, whereas the "word" processes are automatically closed after conversion.

That fixed 30 sec makes me think of a timeout, as if apache couldn't make the COM object end (using apache + php/cgi on windows server).

Do you have an idea ? Thanks in advance !