$logger->setWriters($writerQueue);
// -----------------------------------------------------------------------------
// Create temporary directory
$tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(rand(1, 10000) . __FILE__);
if (is_dir($tempDirectory)) {
    recursiveRemoveDirectory($tempDirectory);
}
$logger->log(Logger::INFO, sprintf('Making temporary directory %s.', $tempDirectory));
mkdir($tempDirectory);
// -----------------------------------------------------------------------------
// Generate temporary documents
$tempFilenames = array();
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_USERNAME)->setPassword(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_PASSWORD)->setService(MailMerge::SERVICE_FREE);
// for LiveDocx Premium, use MailMerge::SERVICE_PREMIUM;
$mailMerge->setLocalTemplate('template.docx');
for ($iteration = 1; $iteration <= $iterations; $iteration++) {
    $tempFilename = sprintf('%s%s%010s.pdf', $tempDirectory, DIRECTORY_SEPARATOR, $iteration);
    $tempFilenames[] = $tempFilename;
    $mailMerge->assign('software', randomString())->assign('licensee', randomString())->assign('company', randomString())->assign('date', Helper::currentDate())->assign('time', Helper::currentTime())->assign('city', randomString())->assign('country', randomString());
    $mailMerge->createDocument();
    file_put_contents($tempFilename, $mailMerge->retrieveDocument('pdf'));
    $logger->log(Logger::INFO, sprintf('Generating temporary document %s.', $tempFilename));
}
unset($mailMerge);
// -----------------------------------------------------------------------------
// Concatenate temporary documents and write output document
$outputFilename = __DIR__ . DIRECTORY_SEPARATOR . 'document-concat.pdf';
$logger->log(Logger::INFO, 'Concatenating temporary documents...');
if (true === concatenatePdfFilenames($tempFilenames, $outputFilename, $processor, $logger)) {
    $logger->log(Logger::INFO, sprintf('...DONE. Saved output document as %s.', basename($outputFilename)));
예제 #2
0
<?php

include_once realpath('../../../../Bootstrap.php');
use ZendService\LiveDocx\DemoHelper as Helper;
use ZendService\LiveDocx\MailMerge;
Helper::printLine(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);
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_USERNAME)->setPassword(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_PASSWORD)->setService(MailMerge::SERVICE_FREE);
// for LiveDocx Premium, use MailMerge::SERVICE_PREMIUM
// -----------------------------------------------------------------------------
$templateName = 'template-1-text-field.docx';
$mailMerge->setLocalTemplate($templateName);
printf('Field names in %s:%s', $templateName, PHP_EOL);
$fieldNames = $mailMerge->getFieldNames();
foreach ($fieldNames as $fieldName) {
    printf('- %s%s', $fieldName, PHP_EOL);
}
// -----------------------------------------------------------------------------
$templateName = 'template-2-text-fields.doc';
$mailMerge->setLocalTemplate($templateName);
printf('%sField names in %s:%s', PHP_EOL, $templateName, PHP_EOL);
$fieldNames = $mailMerge->getFieldNames();
foreach ($fieldNames as $fieldName) {
    printf('- %s%s', $fieldName, PHP_EOL);
}
// -----------------------------------------------------------------------------
$templateName = 'template-block-fields.doc';
$mailMerge->setLocalTemplate($templateName);
printf('%sField names in %s:%s', PHP_EOL, $templateName, PHP_EOL);
$fieldNames = $mailMerge->getFieldNames();
foreach ($fieldNames as $fieldName) {
예제 #3
0
 case 'item.create':
     $item = PodioItem::get($_POST['item_id']);
     $temp_array = array();
     foreach ($item->files as $fs) {
         $temp_array[] = $fs;
         if ($fs->mimetype == 'application/msword') {
             //Get file name withour ext
             $no_ext = substr($fs->name, 0, strpos($fs->name, '.'));
             //Upload file to our server
             $fl = PodioFile::get($fs->file_id);
             $fc = $fl->get_raw();
             file_put_contents($upload_path . $fs->name, $fc);
             //Part with convert files from doc(x) to pdf
             $mailMerge = new MailMerge();
             $mailMerge->setUsername($user)->setPassword($password)->setService(MailMerge::SERVICE_FREE);
             $mailMerge->setLocalTemplate($upload_path . $fs->name);
             $mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9');
             $mailMerge->createDocument();
             $document = $mailMerge->retrieveDocument($need_ext);
             file_put_contents($upload_path . $no_ext . $ext_pdf, $document);
             unset($mailMerge);
             // Attached file pdf to our item
             $f = PodioFile::upload($upload_path . $no_ext . $ext_pdf, $no_ext . $ext_pdf);
             $temp_array[] = $f;
             // Removed temp files
             unlink($upload_path . $fs->name);
             unlink($upload_path . $no_ext . $ext_pdf);
         }
     }
     // Create a new collection for files
     $item->files = new PodioCollection($temp_array);
예제 #4
0
<?php

include_once realpath('../../../../Bootstrap.php');
/**
 * Converting documents between supported formats
 *
 * The primary goal of the Zend Framework LiveDocx component is to populate templates
 * with textual data to generate word processing documents. It can, however,
 * also be used to convert word processing documents between supported formats.
 *
 * For a list of supported file formats see: http://is.gd/6YKDu
 *
 * In this demo application, the file 'document.doc' is converted to 'document.pdf'
 *
 * In a future version of the LiveDocx service, a converter component will be
 * made available.
 */
use ZendService\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_USERNAME)->setPassword(DEMOS_ZENDSERVICE_LIVEDOCX_FREE_PASSWORD)->setService(MailMerge::SERVICE_FREE);
// for LiveDocx Premium, use MailMerge::SERVICE_PREMIUM
$mailMerge->setLocalTemplate('document.doc');
$mailMerge->assign('dummyFieldName', 'dummyFieldValue');
// necessary as of LiveDocx 1.2
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
unset($mailMerge);