Forum


Replies: 5   Views: 6498
Com class doesn't open word file correctly
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 arcmedia  · 19-03-2015 - 10:30

We are generating a Word File and then converting it to PDF via ``transformDocxUsingMSWord``. This works perfectly on our local environment, however fails in production. Here's what happens: 1. Word File is generated correctly 2. $docx->transformDocxUsingMSWord() is executed 3. In MSWordInterface.inc, the transformFormat() method tries to open the file via: $MSWordInstance->Documents->Open($docSource); 4. The class tries to save the document as a pdf via: $MSWordInstance->Documents[1]->SaveAs($docDestination, $code[$extension]); however $MSWordInstance->Documents[1] does not exist. 5. Exception thrown: CRITICAL: Uncaught PHP Exception com_exception: "Source: Microsoft Word
Description: The requested member of the collection does not exist." at C:\[...]\Classes\Phpdocx\Converters\MSWordInterface.inc line 62 {"exception":"[object] (com_exception(code: -2147352567): Source: Microsoft Word
Description: The requested member of the collection does not exist. at C:\\[...]\\Classes\\Phpdocx\\Converters\\MSWordInterface.inc:62)"} [] So the method to open the Word file does not return any error, however doesn't open the file as well.. The server is a Windows Server 2012R2 Standard, running Apache2.4 with Word2010 installed. I reckon that it's something about privileges of the user, however can't find any solution. Any ideas?

Posted by admin  · 20-03-2015 - 08:00

Hello, That error happens when the server is unable to read the source document. Please do these tests: 1. Check that you're using \\ as the file path. As example: C:\\Documents\\document.docx If it doesn't work escape all '\': C:\\\\Documents\\\\document.docx 2. Try setting ActiveDocument instead of Documents[1]. This is: $MSWordInstance->ActiveDocument->SaveAs($docDestination, $code[$extension]); in the MSWordInterface class. Regards.

Posted by arcmedia  · 20-03-2015 - 08:58

Thank you for you reply! Unfortunately your suggestions don't work as well. I have tried every possible combination of file paths (each returning true to file_exists()). The "->ActiveDocument" returns a new Exception: request.CRITICAL: Uncaught PHP Exception com_exception: "Source: Microsoft Word
Description: This command is not available because no document is open." Now searching for server configuration problems. Any pointers/help would be greatly appreciated!

Posted by admin  · 20-03-2015 - 09:16

Hello, Maybe it could be due to a read error access. A good test is to run the same script using the PHP CLI mode, to isolate the problem from the web server. Regards.

Posted by arcmedia  · 20-03-2015 - 12:25

Yes you are right, it is a read access problem. Executing the script via console works perfectly. However, temporarily running Apache using the same user who executed the console program results in the same error..

Posted by arcmedia  · 29-05-2015 - 08:44

Fun fact: The folder ``C:\Windows\SysWOW64\config\systemprofile\`` **must** exist! Otherwise system users cannot call the Word Interop interface and therefore cannot create the PDF. [More on the issue here.](https://social.msdn.microsoft.com/Forums/en-US/0f5448a7-72ed-4f16-8b87-922b71892e07/word-2007-documentsopen-returns-null-in-aspnet?forum=architecturegeneral)