Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Example of how to convert word processing documents, using phpLiveDocx.
- *
- * Supported input formats : doc, docx, rtf & txd.
- * Supported output formats : doc, docx, html, pdf, rtf, txd & txt.
- *
- * In a future version of phpLiveDocx, this functionality will be made available
- * directly in the core API. For the time being, this class offers document
- * conversion with the current version of phpLiveDocx (v1.2).
- *
- * NOTE 1: This class accesses the constants USERNAME and PASSWORD. These are
- * your credentials to the phpLiveDocx service and must have been defined
- * before the class can work. e.g.
- *
- * define ('USERNAME', 'myUsername');
- * define ('PASSWORD', 'myPassword');
- *
- * NOTE 2: The code in this class is for exemplary purposes only. For example,
- * Zend_Service_LiveDocx_MailMerge::setLocalTemplate() and
- * Zend_Service_LiveDocx_MailMerge::createDocument() throw exceptions
- * should something go wrong. In production code, you should therefore
- * use these methods in a try..catch block. This has been left out here
- * to aide debugging and to make the example code as simple as possible.
- */
- class Converter
- {
- /**
- * Convert a word processing document from one format to another
- *
- * @param string $filename File to convert
- * @param string $format Format into which to convert (doc, docx, html, pdf, rtf, txd or txt)
- * @return binary
- */
- public static function convert($filename, $format)
- {
- $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
- $phpLiveDocx->setUsername(USERNAME)
- ->setPassword(PASSWORD);
- $phpLiveDocx->setLocalTemplate($filename);
- $phpLiveDocx->assign('dummyField', 'dummyValue');
- $phpLiveDocx->createDocument();
- return $phpLiveDocx->retrieveDocument($format);
- }
- /**
- * Helper method to return the filename of the converted document
- *
- * @param string $filename File to convert
- * @param string $format Format into which to convert (docx, doc, rtf, txd, pdf, txt)
- * @return string
- */
- public static function getFilename($filename, $format)
- {
- $pattern = sprintf('\.%s$', Zend_Service_LiveDocx::getFormat($filename));
- $replace = '.' . $format;
- return preg_replace("/{$pattern}/", $replace, $filename);
- }
- }
Add Comment
Please, Sign In to add comment