Forum


Replies: 4   Views: 5931
Template output pdf - compatibility mode error
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 weatherworks  · 17-12-2013 - 18:44

Hello, we are trying to use PHPDocX to modify templates and then output them as .pdf. The template conversion works perfectly, but we can't seem to get the pdf output to work properly.



We are using PHPDocX 3.6, and paid for the Pro+ license specifically for PDF export functionality.



We have java installed: java version "1.6.0_26"

Java(TM) SE Runtime Environment (build 1.6.0_26-b03)



PHP Version => 5.3.3-7+squeeze18



Here is the code:




error_reporting(-1);
require_once '/var/www/app/phpdocx/classes/CreateDocx.inc';
$docx = new CreateDocx();
$docx->addTemplate('docx_template.docx');
$docx->addTemplateVariable('TIMESTAMP', date('l F, Y | g:i a'));
$docx->addTemplateVariable('CLIENT', 'Client Name Inc.');
$docx->createDocx('outfile');

try{$docx->transformDocx('outfile.docx','outfile.pdf'); } catch(Exception $e){
echo '<p>Error Caught!</p>';
var_dump($e);
}


When I run this, the .docx gets created, but the PDF creation fails. I had to add in the try/catch block to even see any error, because by default no errors are thrown when PDF conversion fails.



Here's the output from the try/catch block:



"Running in compatibility mode. Unsupported method."



I've tried adding the line that enables compatibility mode, all it does is suppress the exception that gets thrown.



Please let me know how I can disable compatibility mode and/or output the pdf. There are lots of forum posts or documentation that say not to use certian functions when doing PDF conversion... but there's no list of what functions are allowed / not allowed.



 


Posted by jorgelj  · 18-12-2013 - 09:00

Hello,



Please try using the TransformDocAdv class. First create the document:



require_once '/var/www/app/phpdocx/classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addTemplate('docx_template.docx');

$docx->addTemplateVariable('TIMESTAMP', date('l F, Y | g:i a'));

$docx->addTemplateVariable('CLIENT', 'Client Name Inc.');

$docx->createDocx('outfile');



But to do the transformation use the TransformDocAdv class:



$transform = new TransformDocAdv();



$transform->transformDocument('input.docx', 'output.pdf');



Regards. Jorge.


Posted by weatherworks  · 18-12-2013 - 17:03

Jorge,



Thank you for your prompt reply. Unfortounately, your suggestion does not work. I tried sepearting the .docx creating code from the PDF converting code, and it still doesn't work or generate any errors.



Here is the PDF conversion code:



error_reporting(-1);



require_once '/var/www/app/phpdocx/classes/TransformDocAdv.inc';



$transform = new TransformDocAdv();

try{ $transform->transformDocument('outfile.docx','outfile.pdf'); } catch (Exception $e){

    

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

    var_dump($e);

    

}



I am certian that the www-data user has write access to the folder, because the .docx files are getting created with no problem. I am also concerned that the try/catch block is not throwing an exception and that no errors are being displayed despite the conversion function failing.


Posted by jorgelj  · 19-12-2013 - 09:16

Hello,



Please try to run the included example using the CLI mode:



$ php Transform.php



And post any output.



Regards.