Forum


Replies: 2   Views: 4738
Convert from docx to pdf by openoffice 4
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 handoi912  · 20-02-2014 - 11:46

Hello.



I using vesion 3.7 pro+ of phpdocx. My server running linux. I downloaded OpenOffice 4 and run it with headless mode.



My check.php:




  • OK PHP version is 5.4.25-1~dotdeb.0

  • OK Zip support is enabled.

  • OK XSL support is enabled.

  • OK DOM support is enabled.

  • OK XML support is enabled.

  • OK Tidy support is enabled.

  • OK The path examples/docx used by the examples is writable.

  • OK The license is valid for the current domain/server.

  • OK The library can write to temp folder.

  • OK OpenOffice is running in headless mode on port 8100.

    PHPDocX includes OpenOffice but you can download a custom version from http://www.openoffice.org/download



And My code:



<?php

require_once '/var/www/__apps/helpers/phpdocx/classes/CreateDocx.inc';

$data = array(

    '1.1' => str_replace('<img',"<img style='display: none;'",$_POST['tab1_1']),

    '1.2' => str_replace('<img',"<img style='float: right; padding: 50px 0px 10px 10px; width: 282px; height: 600px;'",$_POST['tab1_2']),

    '1.3' =>  str_replace('<h3 class="block-h3">Programme détaillé</h3>','',$_POST['tab1_3']),

    '2.1' => "<div class='tab-pane tab-pane-2-1 block' style='font-size: 11pt;'>".$_POST['tab2_1']."</div>",

    '2.2' => "<div class='tab-pane tab-pane-2-2 block' style='font-size: 11pt;'>".$_POST['tab2_2']."</div>",

    '2.3' => "<div class='tab-pane tab-pane-2-3 block' style='font-size: 11pt;'>".$_POST['tab2_3']."</div>",

    '2.4' => "<div class='tab-pane tab-pane-2-4 block' style='font-size: 11pt;'>".$_POST['tab2_4']."</div>",

);

$name = $_POST['name'];

$tour_day  = $_POST['tour_day'];



    $docx = new CreateDocx();

    $docx->enableCompatibilityMode();

    $docx->addTemplate('/var/www/__apps/helpers/template/vietnam-initiation.docx');

    $docx->replaceTemplateVariableByHTML('h1', 'block', "<span style='color: #8A006C;font-weight: bold;font-size:22pt;margin:0; padding: 0;'>".$_POST['h1']."</span>");

    $docx->replaceTemplateVariableByHTML('days', 'block', "<div class='tour-days' style='font-size: 11pt; color: white;font-weight: bold;'> ".$tour_day."</div>");

    $docx->replaceTemplateVariableByHTML('tab-pane-1-1', 'block', "<div class='tab-pane tab-pane-1-1 block' style='font-size: 11pt;'>".$data['1.1']."</div>");

    $docx->replaceTemplateVariableByHTML('tab-pane-1-2', 'block', "<div class='tab-pane tab-pane-1-2 block' style='font-size: 11pt;'>".$data['1.2']."</div>");

    $docx->replaceTemplateVariableByHTML('tab-pane-1-3', 'block', "<div class='tab-pane tab-pane-1-3 block' style='font-size: 11pt;'>".$data['1.3']."</div>");

    $docx->replaceTemplateVariableByHTML('tab-pane-2-1', 'block', $data['2.1']);

    $docx->replaceTemplateVariableByHTML('tab-pane-2-2', 'block', $data['2.2']);

    $docx->replaceTemplateVariableByHTML('tab-pane-2-3', 'block', $data['2.3']);

    $docx->replaceTemplateVariableByHTML('tab-pane-2-4', 'block', $data['2.4']);

    $docx->createDocx('/var/upload/ideas/tours/output/'.$name);

    if(file_exists('/var/www/upload/ideas/tours/output/'.$name.'.docx')){

        $transform = new TransformDocAdv();

        try{ $transform->transformDocument("/var/www/upload/ideas/tours/output/$name.docx","/var/www/upload/ideas/tours/output/$name.pdf"); } catch (Exception $e){

    

            echo '<p>Error Caught!</p>';

            var_dump($e);

            

        }

        // $transform->transformDocument("/var/www/upload/ideas/tours/output/$name.docx", "/var/www/upload/ideas/tours/output/$name.pdf");

        // echo "1";

    }

     

?>



I created file docx, it 's very good, but can't convert it to pdf. I don't look  error message.



Please help me.


Posted by jorgelj  · 20-02-2014 - 15:14

Hello,



Try to enable the debug mode and run the included example (advanced/Trasform.php) using the CLI mode.



To enable the debug mode check this page:



http://www.phpdocx.com/api-documentation/advanced-conversion-plugin/convert-Word-docx-into-pdf-with-PHP



Regards.