Word to PDF in PHP
Long time took me to find a nice way to convert DOC files to PDF from PHP, not any was enough good.
Finally I found a web service that is for free and you can use it from PHP.
The steps to convert the file are really easy
- Sign in http://www.livedocx.com/ (is for free)
- No you can use the live demo of the site.
- All the files will be stored in the “box”
To use it in php is not so difficult either:
- Download Zend Framework Minimal (18Mb unzipped!!!!!!)
- Download and install the latest version ofphpLiveDocx (611Kb)
- Configure it.
- The script uploads the file twice, one in your server and another in phpLiveDocx (to convert it), later you need to wait a bit for the returning file.
- The conversion works great and fast!
- The uploaded file is not the “box”, better since then you can share the account for many things
Example usage in php
require_once dirname(__FILE__) . '/../../common.php'; require_once dirname(__FILE__) . '/../../Converter.php'; define('PATH_BASE', dirname(__FILE__) ); $inputFilename = PATH_BASE . DIRECTORY_SEPARATOR . 'your_word_file.doc'; // convert this file $outputFormat = 'pdf'; // into this format $outputFilename = Converter::getFilename($inputFilename, $outputFormat); printf('Converting %s to %s... ', basename($inputFilename), basename($outputFilename)); $convertedDocument = Converter::convert($inputFilename, $outputFormat); if (false !== $convertedDocument) { file_put_contents($outputFilename, $convertedDocument); print("DONE.n"); } else { print("ERROR.n"); }
Convert example from wordsample2.doc to wordsample2.pdf
Hope you like this ;)
Related Posts- Open Classifieds 1.7. Release Candidate 2
- phpSEO - Class for better SEO in PHP
- Cache expire Headers in PHP
- PHP Class for better cache - fileCache
- Open Classifieds - Update to latest version 1.7.0.2
- Week in Tweets Ending 2009-05-02
- Review: Update: Kindle 2 ebook reader
- Wordpress Backup
- Essential iPhone Apps That Should Be Free For iPhone 4
- Top Best 100 Incredibly Useful & Free Mac Apps
Help sharing and Flatter me ;)


[...] makes everything more complicated. We already saw how to convert from Word to PDF in PHP and Concatenate PDF in PHP but that’s not [...]