Browse Source

Moved Zend_Service_LiveDocx demos to trunk

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19360 44c647ce-9c0f-0410-b52a-842ac1e357ba
jonathan_maron 16 years ago
parent
commit
ace7c959f9
41 changed files with 1493 additions and 0 deletions
  1. 126 0
      demos/Zend/Service/LiveDocx/Helper.php
  2. 39 0
      demos/Zend/Service/LiveDocx/MailMerge/bitmaps/generate-bitmaps.php
  3. BIN
      demos/Zend/Service/LiveDocx/MailMerge/bitmaps/template-screenshot.png
  4. BIN
      demos/Zend/Service/LiveDocx/MailMerge/bitmaps/template.docx
  5. 2 0
      demos/Zend/Service/LiveDocx/MailMerge/constructors/credentials.ini
  6. 40 0
      demos/Zend/Service/LiveDocx/MailMerge/constructors/hosted-licensed.php
  7. 33 0
      demos/Zend/Service/LiveDocx/MailMerge/constructors/public-zend_config.php
  8. 59 0
      demos/Zend/Service/LiveDocx/MailMerge/constructors/public.php
  9. 255 0
      demos/Zend/Service/LiveDocx/MailMerge/license-agreement/generate-document-concat.php
  10. 97 0
      demos/Zend/Service/LiveDocx/MailMerge/license-agreement/generate-document.php
  11. BIN
      demos/Zend/Service/LiveDocx/MailMerge/license-agreement/template-screenshot.png
  12. BIN
      demos/Zend/Service/LiveDocx/MailMerge/license-agreement/template.docx
  13. 37 0
      demos/Zend/Service/LiveDocx/MailMerge/metafiles/generate-metafiles.php
  14. BIN
      demos/Zend/Service/LiveDocx/MailMerge/metafiles/template-screenshot.png
  15. BIN
      demos/Zend/Service/LiveDocx/MailMerge/metafiles/template.docx
  16. 59 0
      demos/Zend/Service/LiveDocx/MailMerge/supported-fonts/show-supported-fonts-cached.php
  17. 24 0
      demos/Zend/Service/LiveDocx/MailMerge/supported-fonts/show-supported-fonts.php
  18. 68 0
      demos/Zend/Service/LiveDocx/MailMerge/supported-formats/show-supported-formats-cached.php
  19. 33 0
      demos/Zend/Service/LiveDocx/MailMerge/supported-formats/show-supported-formats.php
  20. 95 0
      demos/Zend/Service/LiveDocx/MailMerge/telephone-bill/generate-document.php
  21. BIN
      demos/Zend/Service/LiveDocx/MailMerge/telephone-bill/template-screenshot.png
  22. BIN
      demos/Zend/Service/LiveDocx/MailMerge/telephone-bill/template.doc
  23. 81 0
      demos/Zend/Service/LiveDocx/MailMerge/template-info/list-template-info.php
  24. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-1-text-field-screenshot.png
  25. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-1-text-field.doc
  26. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-1-text-field.docx
  27. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-2-text-fields-screenshot.png
  28. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-2-text-fields.doc
  29. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-2-text-fields.docx
  30. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-block-fields-screenshot.png
  31. BIN
      demos/Zend/Service/LiveDocx/MailMerge/template-info/template-block-fields.doc
  32. 30 0
      demos/Zend/Service/LiveDocx/MailMerge/templates/delete-all.php
  33. 31 0
      demos/Zend/Service/LiveDocx/MailMerge/templates/download.php
  34. 24 0
      demos/Zend/Service/LiveDocx/MailMerge/templates/list.php
  35. BIN
      demos/Zend/Service/LiveDocx/MailMerge/templates/template-1.docx
  36. BIN
      demos/Zend/Service/LiveDocx/MailMerge/templates/template-2.docx
  37. 30 0
      demos/Zend/Service/LiveDocx/MailMerge/templates/template-exists.php
  38. 30 0
      demos/Zend/Service/LiveDocx/MailMerge/templates/upload.php
  39. 6 0
      demos/Zend/Service/LiveDocx/README
  40. 279 0
      demos/Zend/Service/LiveDocx/check-environment.php
  41. 15 0
      demos/Zend/Service/LiveDocx/common.php

+ 126 - 0
demos/Zend/Service/LiveDocx/Helper.php

@@ -0,0 +1,126 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Service
+ * @subpackage LiveDocx
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** Zend_Date **/
+require_once 'Zend/Date.php';
+
+/**
+ * @category   Demos
+ * @package    Demos_Zend_Service
+ * @subpackage LiveDocx
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Demos_Zend_Service_LiveDocx_Helper
+{
+    /**
+     * LiveDocx demo username
+     */
+    const USERNAME = 'zfdemos';
+    
+    /**
+     * LiveDocx demo password
+     */    
+    const PASSWORD = 'fkj3487o4zf35';
+    
+    /**
+     * Line length in characters (used to wrap long lines)
+     */
+    const LINE_LENGTH = 80;
+    
+    /**
+     * Default Locale
+     */
+    const LOCALE = 'en_US';
+    
+    /**
+     * Decorator to format return value of list methods
+     *
+     * @param array $result
+     * @return string
+     */
+    public static function listDecorator($result)
+    {
+        $ret = '';
+        
+        $dateFormat = Zend_Date::RFC_1123;
+        
+        $date = new Zend_Date();
+        $date->setLocale(self::LOCALE);
+        
+        if (count($result) > 0) {
+            foreach ($result as $record) {
+                $date->set($record['createTime']);
+                $createTimeFormatted = $date->get($dateFormat);
+                $date->set($record['modifyTime']);
+                $modifyTimeFormatted = $date->get($dateFormat);
+                $ret .= sprintf('         Filename  : %s%s', $record['filename'], PHP_EOL);
+                $ret .= sprintf('         File Size : %d b%s', $record['fileSize'], PHP_EOL);
+                $ret .= sprintf('     Creation Time : %d (%s)%s', $record['createTime'], $createTimeFormatted, PHP_EOL);
+                $ret .= sprintf('Last Modified Time : %d (%s)%s', $record['modifyTime'], $modifyTimeFormatted, PHP_EOL);
+                $ret .= PHP_EOL;
+            }
+        }
+        unset($date);
+        
+        return $ret;
+    }
+    
+    /**
+     * Decorator to format array
+     *
+     * @param array $result
+     * @return string
+     */
+    public static function arrayDecorator($result)
+    {
+        $ret = '';
+        $count = count($result);
+        if ($count > 0) {
+            for ($i = 0; $i < $count; $i ++) {
+                $ret .= $result[$i];
+                if ($count === ($i + 1)) {
+                    $ret .= '.';
+                } elseif ($count === ($i + 2)) {
+                    $ret .= ' & ';
+                } else {
+                    $ret .= ', ';
+                }
+            }
+        } else {
+            $ret .= 'none';
+        }
+        return $ret;
+    }
+    
+    /**
+     * Wrap the length of long lines
+     * 
+     * @param string $str
+     * @return string
+     */
+    public static function wrapLine($str)
+    {
+        return wordwrap($str, self::LINE_LENGTH);
+    }
+}

+ 39 - 0
demos/Zend/Service/LiveDocx/MailMerge/bitmaps/generate-bitmaps.php

@@ -0,0 +1,39 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+$date = new Zend_Date();
+
+$date->setLocale(Demos_Zend_Service_LiveDocx_Helper::LOCALE);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$phpLiveDocx->setLocalTemplate('template.docx');
+
+$phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9');
+$phpLiveDocx->assign('licensee', 'Daï Lemaitre');
+$phpLiveDocx->assign('company',  'Megasoft Co-operation');
+$phpLiveDocx->assign('date',     $date->get(Zend_Date::DATE_LONG));
+$phpLiveDocx->assign('time',     $date->get(Zend_Date::TIME_LONG));
+$phpLiveDocx->assign('city',     'Lyon');
+$phpLiveDocx->assign('country',  'France');
+
+$phpLiveDocx->createDocument();
+
+// Get all bitmaps
+$bitmaps = $phpLiveDocx->getAllBitmaps(100, 'png');      // zoomFactor, format
+
+// Get just bitmaps in specified range
+//$bitmaps = $phpLiveDocx->getBitmaps(2, 2, 100, 'png');   // fromPage, toPage, zoomFactor, format
+
+foreach ($bitmaps as $pageNumber => $bitmapData) {
+    $filename = sprintf('documentPage%d.png', $pageNumber);
+    file_put_contents($filename, $bitmapData);
+}
+
+unset($phpLiveDocx);

BIN
demos/Zend/Service/LiveDocx/MailMerge/bitmaps/template-screenshot.png


BIN
demos/Zend/Service/LiveDocx/MailMerge/bitmaps/template.docx


+ 2 - 0
demos/Zend/Service/LiveDocx/MailMerge/constructors/credentials.ini

@@ -0,0 +1,2 @@
+username = zfdemos
+password = fkj3487o4zf35

+ 40 - 0
demos/Zend/Service/LiveDocx/MailMerge/constructors/hosted-licensed.php

@@ -0,0 +1,40 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Using Hosted Solution and Fully-Licensed Servers' .
+    PHP_EOL . 
+    PHP_EOL . 'This sample application illustrates how to use Zend_Service_LiveDocx_MailMerge with hosted and fully-licensed LiveDocx servers, by specifying an alternative SOAP client (must be instance of Zend_Soap_Client).' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$mySoapClient = new Zend_Soap_Client(
+    'https://api.example.com/1.2/mailmerge.asmx?WSDL'
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setSoapClient($mySoapClient);
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$phpLiveDocx->getTemplateFormats(); // then call methods as usual
+
+printf('Username : %s%sPassword : %s%s    WSDL : %s%s%s',
+    $phpLiveDocx->getUsername(),
+    PHP_EOL,
+    $phpLiveDocx->getPassword(),
+    PHP_EOL,
+    $phpLiveDocx->getSoapClient()->getWsdl(),
+    PHP_EOL,
+    PHP_EOL
+);
+
+unset($phpLiveDocx, $mySoapClient);

+ 33 - 0
demos/Zend/Service/LiveDocx/MailMerge/constructors/public-zend_config.php

@@ -0,0 +1,33 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Using the Public LiveDocx Service with Zend_Config' .
+    PHP_EOL . 
+    PHP_EOL . 'This sample application illustrates how to use Zend_Service_LiveDocx_MailMerge with a Zend_Config object. This is useful, for example, to store connection credentials in an external ini file.' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$options = new Zend_Config_Ini('credentials.ini');
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge($options);
+
+$phpLiveDocx->getTemplateFormats(); // then call methods as usual
+
+printf('Username : %s%sPassword : %s%s    WSDL : %s%s%s',
+    $phpLiveDocx->getUsername(),
+    PHP_EOL,
+    $phpLiveDocx->getPassword(),
+    PHP_EOL,
+    $phpLiveDocx->getSoapClient()->getWsdl(),
+    PHP_EOL,
+    PHP_EOL
+);
+
+unset($phpLiveDocx, $options);

+ 59 - 0
demos/Zend/Service/LiveDocx/MailMerge/constructors/public.php

@@ -0,0 +1,59 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Using the Free Public Server' .
+    PHP_EOL . 
+    PHP_EOL . 'This sample application illustrates how to use Zend_Service_LiveDocx_MailMerge with the free, public LiveDocx server.' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$phpLiveDocx->getTemplateFormats(); // then call methods as usual
+
+printf('Username : %s%sPassword : %s%s    WSDL : %s%s%s',
+    $phpLiveDocx->getUsername(),
+    PHP_EOL,
+    $phpLiveDocx->getPassword(),
+    PHP_EOL,
+    $phpLiveDocx->getSoapClient()->getWsdl(),
+    PHP_EOL,
+    PHP_EOL
+);
+
+unset($phpLiveDocx);
+
+// -----------------------------------------------------------------------------
+
+// Alternatively, you can pass username and password in the constructor.
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
+    array (
+        'username' => Demos_Zend_Service_LiveDocx_Helper::USERNAME,
+        'password' => Demos_Zend_Service_LiveDocx_Helper::PASSWORD,
+    )
+);
+
+$phpLiveDocx->getTemplateFormats(); // then call methods as usual
+
+printf('Username : %s%sPassword : %s%s    WSDL : %s%s%s',
+    $phpLiveDocx->getUsername(),
+    PHP_EOL,
+    $phpLiveDocx->getPassword(),
+    PHP_EOL,
+    $phpLiveDocx->getSoapClient()->getWsdl(),
+    PHP_EOL,
+    PHP_EOL
+);
+
+unset($phpLiveDocx);

+ 255 - 0
demos/Zend/Service/LiveDocx/MailMerge/license-agreement/generate-document-concat.php

@@ -0,0 +1,255 @@
+#!/usr/bin/php
+<?php
+
+set_time_limit(0);
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+/**
+ * Concatenating PDF files locally - advanced
+ * 
+ * In the case that you wish to generate one output document that contains
+ * several thousand populated templates, it is more efficient to use LiveDocx to
+ * generate a large number of singular PDF files and then to concatenate them
+ * locally, than it is to use the backend service directly.
+ * 
+ * As the size of the output document in such cases can be several hundred
+ * megabytes in size, it would take a long time to transfer all data from the
+ * backend service to the local server. Hence, a local concatenation approach is
+ * more desirable and considerably faster.
+ * 
+ * In this example, the backend service is used to populate a template and
+ * create a large number of documents (see variable $iterations). Then, using a 
+ * 3rd party external command line tool - either pdftk (http://is.gd/4KO72) or 
+ * ghostscript (http://is.gd/4LK3N) - the singular PDF files are concatenated
+ * together locally to create one large output PDF file.
+ *
+ * NOTE: This sample application depends upon either pdftk or ghostscript being
+ *       install on your system. Both are available for Linux and Microsoft
+ *       Windows. Please take a look at the constants EXEC_PDFTK and
+ *       EXEC_GHOSTSCRIPT. You may need to redefine these, if you are running 
+ *       Windows, or if your Linux distribution installs the tools at a different
+ *       location. The specified paths are correct for Debian 5.0.3.
+ */
+
+define('EXEC_PDFTK',       '/usr/bin/pdftk');
+define('EXEC_GHOSTSCRIPT', '/usr/bin/gs');
+
+define('PROCESSOR_PDFTK',       1);
+define('PROCESSOR_GHOSTSCRIPT', 2);
+
+// -----------------------------------------------------------------------------
+
+// Processor to use for concatenation.
+//
+// There are 2 options (only):
+//  
+// o PROCESSOR_PDFTK
+//   - Faster
+//   - Requires little memory (RAM)
+//   - No reduction in file size
+//  
+// o PROCESSOR_GHOSTSCRIPT
+//   - Slower
+//   - Requires lots of memory (RAM)
+//   - Reduction in file size
+//  
+// If you have both installed on your system, PROCESSOR_PDFTK is recommended.
+
+$processor = PROCESSOR_PDFTK;
+
+// Number of documents (populated with random strings) to concatenate.
+
+$iterations = 10;
+
+// -----------------------------------------------------------------------------
+
+// Logger to output status messages
+
+$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
+
+Zend_Registry::set('logger', $logger);
+
+// -----------------------------------------------------------------------------
+
+// Create temporary directory
+
+$tempDirectory = sys_get_temp_dir() . '/' . md5(rand(1, 10000) . __FILE__);
+
+if (is_dir($tempDirectory)) {
+    recursiveRemoveDirectory($tempDirectory);
+}
+
+$logger->log(sprintf('Making temporary directory %s.', $tempDirectory), Zend_Log::INFO);
+
+mkdir($tempDirectory);
+
+// -----------------------------------------------------------------------------
+
+// Generate temporary documents
+
+$tempFilenames = array();
+
+$date = new Zend_Date();
+$date->setLocale(Demos_Zend_Service_LiveDocx_Helper::LOCALE);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$phpLiveDocx->setLocalTemplate('template.docx');
+
+for ($iteration = 1; $iteration <= $iterations; $iteration ++) {
+    
+    $tempFilename = sprintf('%s/%010s.pdf', $tempDirectory, $iteration);
+    $tempFilenames[] = $tempFilename;
+    
+    $phpLiveDocx->assign('software', randomString());
+    $phpLiveDocx->assign('licensee', randomString());
+    $phpLiveDocx->assign('company',  randomString());
+    $phpLiveDocx->assign('date',     $date->now()->get(Zend_Date::DATE_LONG));
+    $phpLiveDocx->assign('time',     $date->now()->get(Zend_Date::TIME_LONG));
+    $phpLiveDocx->assign('city',     randomString());
+    $phpLiveDocx->assign('country',  randomString());
+        
+    $phpLiveDocx->createDocument();
+    
+    file_put_contents($tempFilename, $phpLiveDocx->retrieveDocument('pdf'));
+    
+    $logger->log(sprintf('Generating temporary document %s.', $tempFilename), Zend_Log::INFO);
+}
+
+unset($phpLiveDocx, $date);
+
+// -----------------------------------------------------------------------------
+
+// Concatenate temporary documents and write output document
+
+$outputFilename = './document.pdf';
+
+$logger->log('Concatenating temporary documents...', Zend_Log::INFO);
+
+if (true === concatenatePdfFilenames($tempFilenames, $outputFilename, $processor)) {
+    $logger->log(sprintf('...DONE. Saved output document as %s.', $outputFilename), Zend_Log::INFO);
+} else {
+    $logger->log(sprintf('...ERROR.'), Zend_Log::ERR);
+}
+
+// -----------------------------------------------------------------------------
+
+// Delete temporary directory
+
+$logger->log(sprintf('Deleting temporary directory %s.', $tempDirectory), Zend_Log::INFO);
+
+if (is_dir($tempDirectory)) {
+    recursiveRemoveDirectory($tempDirectory);
+}
+
+// =============================================================================
+
+// Helper functions
+
+/**
+ * Create a random string
+ * 
+ * @param $length
+ * @return string
+ */
+function randomString()
+{
+    $ret = '';
+    
+    $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+    
+    $poolLen   = strlen($pool);
+    $stringLen = rand(5, 25);
+    
+    for ($i = 0; $i < $stringLen; $i ++) {
+        $pos = (rand() % $poolLen);
+        $ret .= $pool{$pos};
+    }
+    
+    return $ret;
+}
+
+/**
+ * Recursively remove directory
+ * 
+ * @param $dir
+ * @return void
+ */
+function recursiveRemoveDirectory($dir)
+{
+    $files = glob($dir . '*', GLOB_MARK);
+    
+    foreach ($files as $file) {
+        if ('/' === substr($file, - 1)) {
+            recursiveRemoveDirectory($file);
+        } else {
+            unlink($file);
+        }
+    }
+    
+    if (is_dir($dir)) {
+        rmdir($dir);
+    }
+}
+
+/**
+ * Concatenate the files in passed array $inputFilenames into one file
+ * $outputFilename, using concatenation processor (external 3rd party command
+ * line tool) specified in $processor
+ * 
+ * @param $inputFilenames
+ * @param $outputFilename
+ * @param $processor
+ * @return boolean
+ */
+function concatenatePdfFilenames($inputFilenames, $outputFilename, $processor = EXEC_PDFTK)
+{
+    $ret = false;
+    
+    $logger = Zend_Registry::get('logger');
+    
+    if (! (is_file(EXEC_PDFTK) || is_file(EXEC_GHOSTSCRIPT))) {
+        $logger->log('Either pdftk or ghostscript are required for this sample application.', Zend_Log::CRIT);
+        exit();
+    }
+    
+    if (is_file($outputFilename)) {
+        unlink($outputFilename);
+    }    
+    
+    switch ($processor) {
+
+        case PROCESSOR_PDFTK :
+            $format  = '%s %s cat output %s';
+            $command = sprintf($format, EXEC_PDFTK, implode($inputFilenames, ' '), $outputFilename);
+        break;        
+        
+        case PROCESSOR_GHOSTSCRIPT :
+            $format  = '%s -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dAutoFilterColorImages=false ';
+            $format .= '-dAutoFilterGrayImages=false -dAutoFilterMonoImages=false ';
+            $format .= '-dColorImageFilter=/FlateEncode -dCompatibilityLevel=1.3 -dEmbedAllFonts=true ';
+            $format .= '-dGrayImageFilter=/FlateEncode -dMaxSubsetPct=100 -dMonoImageFilter=/CCITTFaxEncode ';
+            $format .= '-dSubsetFonts=true -sOUTPUTFILE=%s %s';
+            $command = sprintf($format, EXEC_GHOSTSCRIPT, $outputFilename, implode($inputFilenames, ' '));
+        break;
+            
+        default:
+            $logger->log('Invalid concatenation processor - use PROCESSOR_PDFTK or PROCESSOR_GHOSTSCRIPT only.', Zend_Log::CRIT);
+            exit();
+        break;
+    }
+    
+    $command = escapeshellcmd($command);
+    
+    exec($command);
+    
+    if (is_file($outputFilename) && filesize($outputFilename) > 0) {
+        $ret = true;   
+    }
+
+    return $ret;        
+}

+ 97 - 0
demos/Zend/Service/LiveDocx/MailMerge/license-agreement/generate-document.php

@@ -0,0 +1,97 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+$date = new Zend_Date();
+
+$date->setLocale(Demos_Zend_Service_LiveDocx_Helper::LOCALE);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$phpLiveDocx->setLocalTemplate('template.docx');
+
+$phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9');
+$phpLiveDocx->assign('licensee', 'Henry Döner-Meyer');
+$phpLiveDocx->assign('company',  'Co-Operation');
+$phpLiveDocx->assign('date',     $date->get(Zend_Date::DATE_LONG));
+$phpLiveDocx->assign('time',     $date->get(Zend_Date::TIME_LONG));
+$phpLiveDocx->assign('city',     'Berlin');
+$phpLiveDocx->assign('country',  'Germany');
+
+/**
+ * ALTERNATIVE: Concatenating PDF files locally - basic
+ * 
+ * You can also assign multiple sets of data. In this case, each set of data
+ * will populate the template and the resulting document (one per set of data)
+ * will be appended to the previous document. Thus, in this example, we create
+ * two documents that are concatenated into one PDF file.
+ * 
+ * NOTE: In the case that you wish to generate several thousand documents that
+ *       are concatenated into one PDF, please take a look at the sample
+ *       application 'generate-document-pdftk.php' in this directory.
+ */
+/*
+$fieldValues = array (
+    // set 1
+    array (
+        'software' => 'Magic Graphical Compression Suite v2.5',
+        'licensee' => 'Henry Döner-Meyer',
+        'company'  => 'Megasoft Co-Operation',
+        'date'     => $date->get(Zend_Date::DATE_LONG),
+        'time'     => $date->get(Zend_Date::DATE_LONG),
+        'city'     => 'Berlin',
+        'country'  => 'Germany'
+    ),
+    // set 2
+    array (
+        'software' => 'Magic CAD Suite v1.9',
+        'licensee' => 'Brüno Döner-Meyer',
+        'company'  => 'Future Co-Operation',
+        'date'     => $date->get(Zend_Date::DATE_LONG),
+        'time'     => $date->get(Zend_Date::DATE_LONG),
+        'city'     => 'Berlin',
+        'country'  => 'Germany'
+    )    
+);
+
+$phpLiveDocx->assign($fieldValues);
+
+*/
+
+$documentProperties = array (
+    'title'    => 'License Agreement',
+    'author'   => 'Megasoft Co-operation',
+    'subject'  => 'Magic Graphical Compression Suite v1.9',
+    'keywords' => 'graphics, magical, compression, license'
+);
+
+$phpLiveDocx->setDocumentProperties($documentProperties);
+
+$phpLiveDocx->createDocument();
+
+$document = $phpLiveDocx->retrieveDocument('pdf');
+
+file_put_contents('document.pdf', $document);
+
+/*
+ * ALTERNATIVE: Retrieve document in all supported formats
+ *
+ * You can also retrieve the document in all supported formats. In this case,
+ * the generated document is written to the file system multiple times (one file
+ * per format). This is only for exemplary purposes. In a real-world
+ * application, you would probably decide on one or the other format.
+ */
+/*
+foreach ($phpLiveDocx->getDocumentFormats() as $format) {
+    $document = $phpLiveDocx->retrieveDocument($format);
+    file_put_contents('document.' . $format, $document);
+}
+
+*/
+
+unset($phpLiveDocx);

BIN
demos/Zend/Service/LiveDocx/MailMerge/license-agreement/template-screenshot.png


BIN
demos/Zend/Service/LiveDocx/MailMerge/license-agreement/template.docx


+ 37 - 0
demos/Zend/Service/LiveDocx/MailMerge/metafiles/generate-metafiles.php

@@ -0,0 +1,37 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+$date = new Zend_Date();
+
+$date->setLocale(Demos_Zend_Service_LiveDocx_Helper::LOCALE);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$phpLiveDocx->setFieldValue('software', 'Magic Graphical Compression Suite v1.9');
+$phpLiveDocx->setFieldValue('licensee', 'Henry Döner-Meyer');
+$phpLiveDocx->setFieldValue('company',  'Megasoft Co-operation');
+$phpLiveDocx->setFieldValue('date',     $date->get(Zend_Date::DATE_LONG));
+$phpLiveDocx->setFieldValue('time',     $date->get(Zend_Date::TIME_LONG));
+$phpLiveDocx->setFieldValue('city',     'Bremen');
+$phpLiveDocx->setFieldValue('country',  'Germany');
+
+$phpLiveDocx->createDocument();
+
+// Get all metafiles
+$metaFiles = $phpLiveDocx->getAllMetafiles();
+
+// Get just metafiles in specified range
+//$metaFiles = $phpLiveDocx->getMetafiles(1, 2);    // fromPage, toPage
+
+foreach ($metaFiles as $pageNumber => $metaFileData) {
+    $filename = sprintf('documentPage%d.wmf', $pageNumber);
+    file_put_contents($filename, $metaFileData);
+}
+
+unset($phpLiveDocx);

BIN
demos/Zend/Service/LiveDocx/MailMerge/metafiles/template-screenshot.png


BIN
demos/Zend/Service/LiveDocx/MailMerge/metafiles/template.docx


+ 59 - 0
demos/Zend/Service/LiveDocx/MailMerge/supported-fonts/show-supported-fonts-cached.php

@@ -0,0 +1,59 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+$cacheId = md5(__FILE__);
+
+$cacheFrontendOptions = array(
+    'lifetime' => 2592000, // 30 days
+    'automatic_serialization' => true
+);
+
+$cacheBackendOptions = array(
+    'cache_dir' => dirname(__FILE__) . '/cache'
+);
+
+$cache = Zend_Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions);
+
+if (! $fonts = $cache->load($cacheId)) {
+    
+    // Cache miss. Connect to backend service (expensive).
+    
+    $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+    
+    $phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+    $phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+    
+    $fonts = $phpLiveDocx->getFontNames();
+    
+    $cache->save($fonts, $cacheId);
+    
+    unset($phpLiveDocx);
+    
+} else {
+    
+    // Cache hit. Continue.
+    
+}
+
+unset($cache);
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Supported Fonts' .
+    PHP_EOL . 
+    PHP_EOL . 'The following fonts are installed on the backend server and may be used in templates. Fonts used in templates, which are NOT listed below, will be substituted. If you would like to use a font, which is not installed on the backend server, please contact your LiveDocx provider.' .
+    PHP_EOL . 
+    PHP_EOL . '(Note this method call is cached for maximum performance. The supported formats change very infrequently, hence, they are good candidates to be cached.)' .
+    PHP_EOL . 
+    PHP_EOL . Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($fonts) . 
+    PHP_EOL . 
+    PHP_EOL)
+);
+
+print(PHP_EOL);
+
+unset($phpLiveDocx);

+ 24 - 0
demos/Zend/Service/LiveDocx/MailMerge/supported-fonts/show-supported-fonts.php

@@ -0,0 +1,24 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Supported Fonts' .
+    PHP_EOL . 
+    PHP_EOL . 'The following fonts are installed on the backend server and may be used in templates. Fonts used in templates, which are NOT listed below, will be substituted. If you would like to use a font, which is not installed on the backend server, please contact your LiveDocx provider.' .
+    PHP_EOL . 
+    PHP_EOL . Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($phpLiveDocx->getFontNames()) . 
+    PHP_EOL . 
+    PHP_EOL)
+);
+
+unset($phpLiveDocx);

+ 68 - 0
demos/Zend/Service/LiveDocx/MailMerge/supported-formats/show-supported-formats-cached.php

@@ -0,0 +1,68 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Template, Document and Image Formats' .
+    PHP_EOL . 
+    PHP_EOL . 'The following formats are supported by LiveDocx:' .
+    PHP_EOL .
+    PHP_EOL . '(Note these method calls are cached for maximum performance. The supported formats change very infrequently, hence, they are good candidates to be cached.)' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$cacheId = md5(__FILE__);
+
+$cacheFrontendOptions = array(
+    'lifetime' => 2592000, // 30 days
+    'automatic_serialization' => true
+);
+
+$cacheBackendOptions = array(
+    'cache_dir' => dirname(__FILE__) . '/cache'
+);
+
+$cache = Zend_Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions);
+
+if (! $formats = $cache->load($cacheId)) {
+    
+    // Cache miss. Connect to backend service (expensive).
+    
+    $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+    
+    $phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+    $phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+    
+    $formats = new StdClass();
+    
+    $formats->template = $phpLiveDocx->getTemplateFormats();
+    $formats->document = $phpLiveDocx->getDocumentFormats();
+    $formats->image    = $phpLiveDocx->getImageFormats();
+    
+    $cache->save($formats, $cacheId);
+    
+    unset($phpLiveDocx);
+    
+} else {
+    
+    // Cache hit. Continue.
+    
+}
+
+unset($cache);
+
+printf("Supported TEMPLATE file formats (input)  : %s%s",
+    Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($formats->template), PHP_EOL);
+
+printf("Supported DOCUMENT file formats (output) : %s%s",
+    Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($formats->document), PHP_EOL);
+
+printf("Supported IMAGE file formats (output)    : %s%s",
+    Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($formats->image), PHP_EOL);
+
+print(PHP_EOL);

+ 33 - 0
demos/Zend/Service/LiveDocx/MailMerge/supported-formats/show-supported-formats.php

@@ -0,0 +1,33 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Template, Document and Image Formats' .
+    PHP_EOL . 
+    PHP_EOL . 'The following formats are supported by LiveDocx:' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+printf("Supported TEMPLATE file formats (input)  : %s%s",
+    Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($phpLiveDocx->getTemplateFormats()), PHP_EOL);
+
+printf("Supported DOCUMENT file formats (output) : %s%s",
+    Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($phpLiveDocx->getDocumentFormats()), PHP_EOL);
+
+printf("Supported IMAGE file formats (output)    : %s%s",
+    Demos_Zend_Service_LiveDocx_Helper::arrayDecorator($phpLiveDocx->getImageFormats()), PHP_EOL);
+
+print PHP_EOL;
+    
+unset($phpLiveDocx);

+ 95 - 0
demos/Zend/Service/LiveDocx/MailMerge/telephone-bill/generate-document.php

@@ -0,0 +1,95 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+$date = new Zend_Date();
+
+$date->setLocale(Demos_Zend_Service_LiveDocx_Helper::LOCALE);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+/*
+ * ALTERNATIVE: Specify username and password in constructor
+ */
+/*
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
+    array (
+        'username' => Demos_Zend_Service_LiveDocx_Helper::USERNAME,
+        'password' => Demos_Zend_Service_LiveDocx_Helper::PASSWORD
+    )
+);
+*/
+
+$phpLiveDocx->setLocalTemplate('template.doc');
+
+
+$phpLiveDocx->assign('customer_number', sprintf("#%'10s",  rand(0,1000000000)));
+$phpLiveDocx->assign('invoice_number',  sprintf("#%'10s",  rand(0,1000000000)));
+$phpLiveDocx->assign('account_number',  sprintf("#%'10s",  rand(0,1000000000)));
+
+
+$billData = array (  
+    'phone'         => '+22 (0)333 444 555',
+    'date'          => $date->get(Zend_Date::DATE_LONG),
+    'name'          => 'James Henry Brown',
+    'service_phone' => '+22 (0)333 444 559',
+    'service_fax'   => '+22 (0)333 444 558',
+    'month'         => sprintf('%s %s', $date->get(Zend_Date::MONTH_NAME), $date->get(Zend_Date::YEAR)),
+    'monthly_fee'   =>  '15.00',
+    'total_net'     =>  '19.60',
+    'tax'           =>  '19.00',
+    'tax_value'     =>   '3.72',
+    'total'         =>  '23.32'
+);
+
+$phpLiveDocx->assign($billData);
+
+
+$billConnections = array(
+    array(
+        'connection_number'   => '+11 (0)222 333 441',
+        'connection_duration' => '00:01:01',
+        'fee'                 => '1.15'
+    ),
+    array(
+        'connection_number'   => '+11 (0)222 333 442',
+        'connection_duration' => '00:01:02',
+        'fee'                 => '1.15'
+    ),
+    array(
+        'connection_number'   => '+11 (0)222 333 443', 
+        'connection_duration' => '00:01:03', 
+        'fee'                 => '1.15'
+    ),
+    array(
+        'connection_number'   => '+11 (0)222 333 444',
+        'connection_duration' => '00:01:04',
+        'fee'                 => '1.15'
+    )
+);
+
+$phpLiveDocx->assign('connection', $billConnections);
+
+
+$documentProperties = array (
+    'title'    => sprintf('Telephone Invoice (%s)', $billData['name']),
+    'author'   => 'TIS Telecom', 
+    'subject'  => sprintf('Your telephone invoice for %s', $billData['month']),
+    'keywords' => sprintf('Telephone, Payment, Invoice, %s', $billData['month'])
+);
+
+$phpLiveDocx->setDocumentProperties($documentProperties);
+
+
+$phpLiveDocx->createDocument();
+
+$document = $phpLiveDocx->retrieveDocument('pdf');
+
+unset($phpLiveDocx);
+
+file_put_contents('document.pdf', $document);

BIN
demos/Zend/Service/LiveDocx/MailMerge/telephone-bill/template-screenshot.png


BIN
demos/Zend/Service/LiveDocx/MailMerge/telephone-bill/template.doc


+ 81 - 0
demos/Zend/Service/LiveDocx/MailMerge/template-info/list-template-info.php

@@ -0,0 +1,81 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Field and Block Field Names (merge fields)' .
+    PHP_EOL . 
+    PHP_EOL . 'The following templates contain the listed field or block field names:' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+// -----------------------------------------------------------------------------
+
+$templateName = 'template-1-text-field.docx';
+
+$phpLiveDocx->setLocalTemplate($templateName);
+
+printf('Field names in %s:%s', $templateName, PHP_EOL);
+
+$fieldNames = $phpLiveDocx->getFieldNames();
+foreach ($fieldNames as $fieldName) {
+    printf('- %s%s', $fieldName, PHP_EOL);   
+}
+
+// -----------------------------------------------------------------------------
+
+$templateName = 'template-2-text-fields.doc';
+
+$phpLiveDocx->setLocalTemplate($templateName);
+
+printf('%sField names in %s:%s', PHP_EOL, $templateName, PHP_EOL);
+
+$fieldNames = $phpLiveDocx->getFieldNames();
+foreach ($fieldNames as $fieldName) {
+    printf('- %s%s', $fieldName, PHP_EOL);     
+}
+
+// -----------------------------------------------------------------------------
+
+$templateName = 'template-block-fields.doc';
+
+$phpLiveDocx->setLocalTemplate($templateName);
+
+printf('%sField names in %s:%s', PHP_EOL, $templateName, PHP_EOL);
+
+$fieldNames = $phpLiveDocx->getFieldNames();
+foreach ($fieldNames as $fieldName) {
+    printf('- %s%s', $fieldName, PHP_EOL);     
+}
+
+printf('%sBlock names in %s:%s', PHP_EOL, $templateName, PHP_EOL);
+
+$blockNames = $phpLiveDocx->getBlockNames();
+foreach ($blockNames as $blockName) {
+    printf('- %s%s', $blockName, PHP_EOL);    
+}
+
+printf('%sBlock field names in %s:%s', PHP_EOL, $templateName, PHP_EOL);
+
+foreach ($blockNames as $blockName) {
+    $blockFieldNames = $phpLiveDocx->getBlockFieldNames($blockName);
+    foreach ($blockFieldNames as $blockFieldName) {
+        printf('- %s::%s%s', $blockName, $blockFieldName, PHP_EOL);          
+    }
+}
+
+print(PHP_EOL);
+
+// -----------------------------------------------------------------------------
+
+unset($phpLiveDocx);

BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-1-text-field-screenshot.png


BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-1-text-field.doc


BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-1-text-field.docx


BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-2-text-fields-screenshot.png


BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-2-text-fields.doc


BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-2-text-fields.docx


BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-block-fields-screenshot.png


BIN
demos/Zend/Service/LiveDocx/MailMerge/template-info/template-block-fields.doc


+ 30 - 0
demos/Zend/Service/LiveDocx/MailMerge/templates/delete-all.php

@@ -0,0 +1,30 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Deleting All Remotely Stored Templates' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$counter = 1;
+foreach ($phpLiveDocx->listTemplates() as $result) {
+    printf('%d) %s', $counter, $result['filename']);
+    $phpLiveDocx->deleteTemplate($result['filename']);
+    print(' - DELETED.' . PHP_EOL);
+    $counter++;
+}
+
+print(PHP_EOL);
+
+unset($phpLiveDocx);

+ 31 - 0
demos/Zend/Service/LiveDocx/MailMerge/templates/download.php

@@ -0,0 +1,31 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Downloading Remotely Stored Templates' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+$counter = 1;
+foreach ($phpLiveDocx->listTemplates() as $result) {
+    printf('%d) %s', $counter, $result['filename']);
+    $template = $phpLiveDocx->downloadTemplate($result['filename']);
+    file_put_contents('downloaded-' . $result['filename'], $template);
+    print(" - DOWNLOADED.\n");
+    $counter++;
+}
+
+print(PHP_EOL);
+
+unset($phpLiveDocx);

+ 24 - 0
demos/Zend/Service/LiveDocx/MailMerge/templates/list.php

@@ -0,0 +1,24 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Remotely Stored Templates' .
+    PHP_EOL . 
+    PHP_EOL . 'The following templates are currently stored on the LiveDocx server:' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+print(Demos_Zend_Service_LiveDocx_Helper::listDecorator($phpLiveDocx->listTemplates()));
+
+unset($phpLiveDocx);

BIN
demos/Zend/Service/LiveDocx/MailMerge/templates/template-1.docx


BIN
demos/Zend/Service/LiveDocx/MailMerge/templates/template-2.docx


+ 30 - 0
demos/Zend/Service/LiveDocx/MailMerge/templates/template-exists.php

@@ -0,0 +1,30 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Checking For Remotely Stored Templates' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+print('Checking whether a template is available... ');
+if (true === $phpLiveDocx->templateExists('template-1.docx')) {
+    print('EXISTS. ');
+} else {
+    print('DOES NOT EXIST. ');
+}
+print('DONE' . PHP_EOL);
+
+print(PHP_EOL);
+
+unset($phpLiveDocx);

+ 30 - 0
demos/Zend/Service/LiveDocx/MailMerge/templates/upload.php

@@ -0,0 +1,30 @@
+#!/usr/bin/php
+<?php
+
+require_once dirname(__FILE__) . '/../../common.php';
+
+
+system('clear');
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(
+    PHP_EOL . 'Uploading Locally Stored Templates to Server' .
+    PHP_EOL .
+    PHP_EOL)
+);
+
+$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
+
+$phpLiveDocx->setUsername(Demos_Zend_Service_LiveDocx_Helper::USERNAME);
+$phpLiveDocx->setPassword(Demos_Zend_Service_LiveDocx_Helper::PASSWORD);
+
+print('Uploading template... ');
+$phpLiveDocx->uploadTemplate('template-1.docx');
+print('DONE.' . PHP_EOL);
+
+print('Uploading template... ');
+$phpLiveDocx->uploadTemplate('template-2.docx');
+print('DONE.' . PHP_EOL);
+
+print(PHP_EOL);
+
+unset($phpLiveDocx);

+ 6 - 0
demos/Zend/Service/LiveDocx/README

@@ -0,0 +1,6 @@
+Zend_Service_LiveDocx Demonstration Applications
+------------------------------------------------
+
+Before these demonstration applications can be used, you must set the path to your locally installed Zend Framework and Zend Framework Standard Incubator in lines 7 and 8 of "common.php".
+
+Everything else will be set up automatically.

+ 279 - 0
demos/Zend/Service/LiveDocx/check-environment.php

@@ -0,0 +1,279 @@
+#!/usr/bin/php
+<?php
+
+include_once './common.php';
+
+define('TEST_PASS',       'PASS');
+define('TEST_FAIL',       'FAIL');  
+
+define('MIN_PHP_VERSION', '5.2.4');
+define('MIN_ZF_VERSION',  '1.8.0');
+
+define('SOCKET_TIMEOUT',   5); // seconds
+
+$failed  = false;
+$counter = 1;
+
+// -----------------------------------------------------------------------------
+
+ini_set('default_socket_timeout', SOCKET_TIMEOUT);
+
+printf('%sZend_Service_LiveDocx Environment Checker%s%s', PHP_EOL, PHP_EOL, PHP_EOL);
+
+// -----------------------------------------------------------------------------
+
+printLine($counter, sprintf('Checking OS (%s)', PHP_OS), TEST_PASS);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if ('cli' === strtolower(PHP_SAPI)) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, sprintf('Checking SAPI (%s)', PHP_SAPI), $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (1 === version_compare(PHP_VERSION, MIN_PHP_VERSION)) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, sprintf('Checking PHP version (%s)', PHP_VERSION), $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+printLine($counter, sprintf('Checking memory limit (%s)', ini_get('memory_limit')), TEST_PASS);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (in_array('http', stream_get_wrappers())) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking HTTP stream wrapper', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (in_array('https', stream_get_wrappers())) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking HTTPS stream wrapper', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (true === method_exists('Zend_Debug', 'dump')) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking Zend Framework path', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (1 === version_compare(Zend_Version::VERSION, MIN_ZF_VERSION)) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, sprintf('Checking Zend Framework version (%s)', Zend_Version::VERSION), $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (extension_loaded('soap')) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking SOAP extension', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (extension_loaded('dom')) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking DOM extension', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (extension_loaded('simplexml')) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking SimpleXML extension', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (extension_loaded('libxml')) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking libXML extension', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+$geoData = @file_get_contents('http://ipinfodb.com/ip_query.php');
+
+$keys = array (
+    'Ip'          => 'IP address',
+    'City'        => 'city',
+    'RegionName'  => 'region',
+    'CountryName' => 'country'
+);
+
+if (false !== $geoData) {
+    $simplexml = new SimpleXMLElement($geoData);
+    foreach ($keys as $key => $value) {
+        printLine($counter, sprintf('Checking your %s (%s)', $keys[$key], $simplexml->$key), TEST_PASS);
+        $counter ++;
+    }
+} else {
+    printLine($counter, 'Checking your geo data', TEST_FAIL);
+    $failed = true;
+}
+
+// -----------------------------------------------------------------------------
+
+$microtime = microtime(true);
+
+if (false !== @file_get_contents(Zend_Service_LiveDocx_MailMerge::ENDPOINT)) {
+    $duration = microtime(true) - $microtime;
+    $result = TEST_PASS;
+} else {
+    $duration = -1;
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, sprintf('Checking backend WSDL (%01.2fs)', $duration), $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (defined('Demos_Zend_Service_LiveDocx_Helper::USERNAME') &&
+    defined('Demos_Zend_Service_LiveDocx_Helper::PASSWORD')) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, 'Checking backend credentials are defined', $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+$errorMessage = null;
+
+try {
+    $microtime = microtime(true);
+    $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
+        array (
+            'username' => Demos_Zend_Service_LiveDocx_Helper::USERNAME,
+            'password' => Demos_Zend_Service_LiveDocx_Helper::PASSWORD
+        )
+    );
+    $duration = microtime(true) - $microtime;
+} catch (Zend_Service_LiveDocx_Exception $e) {
+    $duration = -1;
+    $errorMessage = $e->getMessage();    
+}
+
+if (is_null($errorMessage)) {
+    $result = TEST_PASS;
+} else {
+    $result = TEST_FAIL;
+    $failed = true;
+}
+
+printLine($counter, sprintf('Instantiating Zend_Service_LiveDocx_MailMerge object (%01.2fs)', $duration), $result);
+
+$counter ++;
+
+// -----------------------------------------------------------------------------
+
+if (true === $failed) {
+    $message = 'One or more tests failed. The web server environment, in which this script is running, does not meet the requirements for Zend_Service_LiveDocx_*.';
+} else {
+    $message = 'Congratulations! All tests passed. The server environment, in which this script is running, is suitable for Zend_Service_LiveDocx_*.';
+}
+
+print(Demos_Zend_Service_LiveDocx_Helper::wrapLine(PHP_EOL . $message . PHP_EOL . PHP_EOL));
+
+// -----------------------------------------------------------------------------
+
+/**
+ * Print result line
+ *
+ * @param $counter
+ * @param $testString
+ * @param $testResult
+ */
+function printLine($counter, $testString, $testResult)
+{
+    $lineLength = Demos_Zend_Service_LiveDocx_Helper::LINE_LENGTH;
+    
+    //                        counter     result
+    $padding = $lineLength - (4 + strlen(TEST_PASS));
+    
+    $counter    = sprintf('%2s: ', $counter);
+    $testString = str_pad($testString, $padding, '.', STR_PAD_RIGHT);
+    
+    printf('%s%s%s%s', $counter, $testString, $testResult, PHP_EOL);
+}
+
+// -----------------------------------------------------------------------------

+ 15 - 0
demos/Zend/Service/LiveDocx/common.php

@@ -0,0 +1,15 @@
+<?php
+
+// Turn up error reporting
+error_reporting (E_ALL|E_STRICT);
+
+// Set path to libraries
+set_include_path ('/usr/share/php-libs/zf/ZendFramework-1.9.5/library' . PATH_SEPARATOR .
+                  '/usr/share/ZendFramework-Incubator/library'         . PATH_SEPARATOR);
+
+// Demos_Zend_Service_LiveDocx_Helper
+require_once dirname(__FILE__) . '/Helper.php';
+
+// Set autoloader to autoload libraries
+require_once 'Zend/Loader/Autoloader.php';
+$autoloader = Zend_Loader_Autoloader::getInstance();