Phpdocx / openoffice

Hi, I have a customer who wants to generate adobe PDF files from Microsoft word .DOCX templates and mySQL data fields (kind of a mail-merge sorta thing) - The idea being that db fields are extracted then substituted for key text in the Word Template, the file is then saved as a Word doc and converted to PDF for printing as a good old fashioned letter.(exported as PDF so that the original word document cannot be edited).

Now then, I have found a commercial product (phpdocx) which allows me to do exactly this, great! I thought… However, the PDF conversion (it turns out) is done by basically installing a complete version of OpenOffice in a sub-folder of the website, and running OpenOffice in a “headless” state.

Is this something I’d even be allowed to do on a dreamhost shared server? (it seems to me like it’s probably going to have a much heavier impact than your average PHP script)

If I try to run Open Office in this fashion am I likely to run into trouble with Dreamhost techs? (I don’t want to down a server just trying to make a PDF!)

You’re welcome to give it a try — it won’t take the server down or anything — but it’s unlikely to work on a shared hosting account, as OpenOffice will probably need more memory to start up than we make available. (OpenOffice is kind of a pig.) You may have better luck on a DreamHost VPS or dedicated server.

Hmm - I seem to be failing at the first hurdle - phpdocx is dependent upon a couple of extensions for PHP…

You have to install Zip extension for PHP
You need to install Tidy extension for PHP if you want to use HTML or PDF features.

Is this something I can do?

Yes. See the directions on our wiki entry for PHP.ini, specifically the directions for loading PHP 5.3 extensions. I’m pretty sure that both the zip and tidy extensions are compiled, so you will just need to add the configuration directives to start loading them. (You will need to switch your domain to PHP 5.3 if it is not already.)

Cool, is there any way I can find out a list of available compiled extensions (so I can find out what the filenames are?)

The following extensions are preinstalled for our build of PHP 5.3. (Some of them are loaded by default, some are not.)

To see the list yourself:

Thank you! OK, so I created the home/username/.php/5.3 folder, added the phprc file within it and added

extension =
extension =

to the file, I then saved it.
The next line says that I “may need to restart the server” - ermmm… How do I do that?

From a shell,

Or just wait a few minutes.

Ok, done that, so how do I tell if they’re installed? because the “Check.php” script provided by phpdocx suggests I still need to install them… confusedface
This is the check it’s running…

<?php /* * PHP Configuration test */ $output = ''; $break = isset($_SERVER['HTTP_USER_AGENT']) ? '
' : PHP_EOL; /* * Checking PHP Version */ $version = explode('.', PHP_VERSION); $iPhpVersion = $version[0] * 10000 + $version[1] * 100 + $version[2]; if ($iPhpVersion < 50000) { $output .= 'Your PHP version (' . PHP_VERSION . '), is too old, update to PHP 5' . $break; } else { $output .= 'Your PHP version is ' . PHP_VERSION . ' => OK' . $break; /* * Checking necessary packages */ //ZipArchive if (!phpversion('zip')) { $output .= 'You have to install Zip extension for PHP' . $break; } else { $output .= 'Your Zip extension version is ' . phpversion('zip') . ' => OK' . $break; } //XSL if (!phpversion('xsl')) { $output .= 'You have to install XSL extension for PHP' . $break; } else { $output .= 'Your XSL extension version is ' . phpversion('xsl') . ' => OK' . $break; } //Tidy if (!phpversion('tidy')) { $output .= 'You need to install Tidy extension for PHP if you want to use HTML or PDF features.' . $break; } else { $output .= 'Your Tidy extension version is ' . phpversion('tidy') . ' => OK' . $break; } } echo $output; ?>

I’m slightly perplexed as I’m running the domain under php5.3 but it’s telling me I have 5.2.17… you’veBeenBAMBOOZLED

Could this be down to the fact that I’m installing the php5.3 stuff at home/username/, but my domain is just one (of many) subfolders?

Are you running this check from the commandline?

yes I am

The CLI runs as 5.2. Try calling the test using $ /usr/local/bin/php-5.3 [check].php

interesting! - got this via the browser…

Your PHP version is 5.3.13 => OK
Your Zip extension version is 1.9.1 => OK
Your XSL extension version is 0.1 => OK
Your Tidy extension version is 2.0 => OK

And, yes !!! Result! - this via your suggestion…

Your PHP version is 5.3.13 => OK
Your Zip extension version is 1.9.1 => OK
Your XSL extension version is 0.1 => OK
Your Tidy extension version is 2.0 => OK

If your script is dropping to the commandline to do it’s work, create an alias for PHP in .bashrc to point at the 5.3 version.

Hi - I think this might be my problem - Could you please explain how to do this?

Hi - I’ve raised this question to a less specific level of the forum as I’m still none the wiser - please see this thread:

Something like:

in your .bashrc file will probably do the trick. Very easy way to do this is:

Be sure to use >> not just > as the latter will overwrite your existing .bashrc file, if you have one. >> makes sure it’s added to the end of the file if it already exists…