Forum


Replies: 2   Views: 5066
Problems with transformdocument()
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 AndrewCooper  · 28-06-2016 - 10:50

Hi,

I've got the following code.

$this->transform = new Phpdocx\Transform\TransformDocAdvLibreOffice();
    
    try { 
      $dest = "/OriginSystems/cache/application/Updraft/administrator/" . $uniqueReferenceID . ".pdf";
      error_log("FileName: " . $proc->getFileName());
      error_log("Destination: $dest");
      $this->transform->transformDocument($proc->getFileName(), 
        $dest,
        "/OriginSystems/cache/application/Updraft/administrator",
        array("debug" => true)
      );
    } catch (Exception $e) {
      error_log($e->getMessage());
    }

The resulting PHP log looks like this.

[28-Jun-2016 11:27:09 Africa/Johannesburg] FileName: /OriginSystems/cache/application/Updraft/administrator/10305949.docx
[28-Jun-2016 11:27:09 Africa/Johannesburg] Destination: /OriginSystems/cache/application/Updraft/administrator/10305949.pdf

As you can see, in this case I'm simply attempting to transform an existing Docx document into a PDF document. Nothing terribly fancy.

I'm using CentOS 7 as the server operating system and I've installed LibreOffice via Yum. My Phpdocx config file has the following in it.

; libreoffice or openoffice
method = "libreoffice"

; libreoffice installation path, absolute path
path = "/usr/bin/soffice"

The file, soffice, exists and works. However, when I run the PHP script I get the following error:

<Entry reference="REF_577242eed8076" TimeStamp="2016/06/28 11:27:10" Category="Exception" Type="Error"><![CDATA[

Description         rename(/OriginSystems/cache/application/Updraft/administrator/10305949.pdf,/OriginSystems/cache/application/Updraft/administrator/10305949.pdf): No such file or directory
File                /webdevroot/Updraft/web/internal/Library/docx/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvLibreOffice.inc
Line                140
Class               BasicException
Category            Warning
Stack               
       8  /webdevroot/Updraft/web/internal/Library/Basics.php   541                                                     newFromError
       6  /webdevroot/Updraft/web/internal/Library/docx/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvLibreOffice.inc   140    rename
       5  /webdevroot/Updraft/web/internal/System/Common/LawDOCX.php   31                                               transformDocument
       4  /webdevroot/Updraft/web/internal/System/Administrator/AdmDraftOutputs.php   70                                __construct
       3  /webdevroot/Updraft/web/internal/System/Administrator/UIvalidate.php   506                                    __construct
       2  /webdevroot/Updraft/web/internal/Library/LibAjax.php   136                                                    generate
       1  /webdevroot/Updraft/web/external/System/Administrator/a.php   19                                              execute

UI                  Administration console
Customer            RGN001 - Origin Systems
User                Dev User    root   (50847)
Code                2
When                2016/06/28 11:27:10
Cookies
     name                                              value                                             
     xbrF                                              v5ha8jfikg734j2cijfvv1adc3                        
     ccof                                              RGN001                                            
     ZDEDebuggerPresent                                php,phtml,php3                                    
Client IP           192.168.56.100
URL called          https://dev.originsystems.co.za:10088/a.php?i=UIvalidate&m=generate&id=7387908&ivt=0&dvt=1&X=1c47920723ee049bc7b962f0c402a434
Referred by         https://dev.originsystems.co.za:10088/i.php?i=UIvalidate&m=displayPage&P=T&id=7387908&X=dca2e65156b0989c7908d0f7ee520b04
]]></Entry>
---------------------------------------------------------------------------------------------------------------

 

As you can see, the rename() command is failing because the file indicated in the first parameter doesn't exist. This is correct. I've checked afterwards and it doesn't exist.  When I run the transform command that is being sent to passthru() in the terminal as root, everything works quite well. When I run the same command as any other user I get a permissions error.

/usr/bin/soffice: line 56: cd: /root: Permission denied

This means (I think) that the PDF file isn't getting created in the first place due to permissions and so that the rename function bombs. I can't figure out what the permissions problem is though. Both the target and destination directories are usable by the web server. The Docx file is generated by Phpdocx and it is writing to that folder fine. I've also changed the tmp folder to the folder that the wev server has permissions to access as well.  Am I missing something with the permissions?  I did a straight install of LibreOffice. No weirdness at all.

Thanks,

Andrew