Exemplo n.º 1
0
<?php

include_once realpath('../../../../Bootstrap.php');
use ZendService\LiveDocx\DemoHelper as Helper;
use ZendService\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZENDSERVICE_LIVEDOCX_PREMIUM_USERNAME)->setPassword(DEMOS_ZENDSERVICE_LIVEDOCX_PREMIUM_PASSWORD)->setService(MailMerge::SERVICE_PREMIUM);
$mailMerge->setLocalTemplate('template.docx');
$mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9')->assign('licensee', 'Henry Döner-Meyer')->assign('company', 'Co-Operation')->assign('date', Helper::currentDate())->assign('time', Helper::currentTime())->assign('city', 'Berlin')->assign('country', 'Germany');
// Available on premium service only
$mailMerge->setDocumentPassword('aaaaaaaaaa');
// Available on premium service only
$mailMerge->setDocumentAccessPermissions(array('AllowHighLevelPrinting', 'AllowExtractContents'), 'myDocumentAccessPassword');
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
unset($mailMerge);
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)));
} else {
    $logger->log(Logger::ERR, sprintf('...ERROR.'));
}
// -----------------------------------------------------------------------------
Exemplo n.º 3
0
 $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);
 // Save the item to Podio
Exemplo n.º 4
0
<?php

include_once realpath('../../../../Bootstrap.php');
use ZendService\LiveDocx\DemoHelper as Helper;
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
/**
 * Image Source:
 * iStock_000003413016Medium_business-man-with-hands-up.jpg
 */
$photoFilename = __DIR__ . '/dailemaitre.jpg';
$photoFile = basename($photoFilename);
if (!$mailMerge->imageExists($photoFile)) {
    // pass image file *without* path
    $mailMerge->uploadImage($photoFilename);
    // pass image file *with* path
}
$mailMerge->setLocalTemplate('template.docx');
$mailMerge->assign('name', 'Daï Lemaitre')->assign('company', 'Megasoft Co-operation')->assign('date', Helper::currentDate())->assign('image:photo', $photoFile);
// pass image file *without* path
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
$mailMerge->deleteImage($photoFilename);
unset($mailMerge);
Exemplo n.º 5
0
<?php

include_once realpath('../../../../Bootstrap.php');
use ZendService\LiveDocx\DemoHelper as Helper;
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('template.docx');
$mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9')->assign('licensee', 'Daï Lemaitre')->assign('company', 'Megasoft Co-operation')->assign('date', Helper::currentDate())->assign('time', Helper::currentTime())->assign('city', 'Lyon')->assign('country', 'France');
$mailMerge->createDocument();
// Get all bitmaps
$bitmaps = $mailMerge->getAllBitmaps(100, 'png');
// zoomFactor, format
// Get just bitmaps in specified range
//$bitmaps = $mailMerge->getBitmaps(2, 2, 100, 'png');   // fromPage, toPage, zoomFactor, format
foreach ($bitmaps as $pageNumber => $bitmapData) {
    $filename = sprintf('document-page-%d.png', $pageNumber);
    file_put_contents($filename, $bitmapData);
}
unset($mailMerge);
Exemplo n.º 6
0
<?php

include_once realpath('../../../../Bootstrap.php');
use ZendService\LiveDocx\DemoHelper as Helper;
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('template.doc');
$mailMerge->assign('customer_number', sprintf("#%'10s", rand(0, 1000000000)))->assign('invoice_number', sprintf("#%'10s", rand(0, 1000000000)))->assign('account_number', sprintf("#%'10s", rand(0, 1000000000)));
$billData = array('phone' => '+22 (0)333 444 555', 'date' => Helper::currentDate(), 'name' => 'James Henry Brown', 'service_phone' => '+22 (0)333 444 559', 'service_fax' => '+22 (0)333 444 558', 'month' => Helper::currentMonthYear(), 'monthly_fee' => '15.00', 'total_net' => '19.60', 'tax' => '19.00', 'tax_value' => '3.72', 'total' => '23.32');
$mailMerge->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'));
$mailMerge->assign('connection', $billConnections);
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('pdf');
unset($mailMerge);
file_put_contents('document.pdf', $document);
Exemplo n.º 7
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);