コード例 #1
0
ファイル: generate-bitmaps.php プロジェクト: alab1001101/zf2
<?php

require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Date\Date;
use Zend\Service\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$mailMerge->setLocalTemplate('template.docx');
$mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9')->assign('licensee', 'Daï Lemaitre')->assign('company', 'Megasoft Co-operation')->assign('date', Date::now()->toString(Date::DATE_LONG))->assign('time', Date::now()->toString(Date::TIME_LONG))->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);
コード例 #2
0
ファイル: generate-metafiles.php プロジェクト: stunti/zf2
<?php

require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Date\Date;
use Zend\Service\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$mailMerge->setLocalTemplate('template.docx');
$mailMerge->setFieldValue('software', 'Magic Graphical Compression Suite v1.9')->setFieldValue('licensee', 'Henry Döner-Meyer')->setFieldValue('company', 'Megasoft Co-operation')->setFieldValue('date', Date::now()->toString(Date::DATE_LONG))->setFieldValue('time', Date::now()->toString(Date::TIME_LONG))->setFieldValue('city', 'Bremen')->setFieldValue('country', 'Germany');
$mailMerge->createDocument();
// Get all metafiles
$metaFiles = $mailMerge->getAllMetafiles();
// Get just metafiles in specified range
//$metaFiles = $mailMerge->getMetafiles(1, 2);    // fromPage, toPage
foreach ($metaFiles as $pageNumber => $metaFileData) {
    $filename = sprintf('document-page-%d.wmf', $pageNumber);
    file_put_contents($filename, $metaFileData);
}
unset($mailMerge);
コード例 #3
0
ファイル: DateObjectTest.php プロジェクト: stunti/zf2
 /**
  * Test for _getTime
  */
 public function test_getTime()
 {
     $date = new DateObjectTestHelper(Date::now());
     $time = $date->_getTime();
     $diff = abs(time() - $time);
     $this->assertTrue($diff < 2, "Zend_Date_DateObject->_getTime() returned a significantly " . "different timestamp than expected: {$diff} seconds");
 }
コード例 #4
0
$tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(rand(1, 10000) . __FILE__);
if (is_dir($tempDirectory)) {
    recursiveRemoveDirectory($tempDirectory);
}
$logger->log(sprintf('Making temporary directory %s.', $tempDirectory), Logger::INFO);
mkdir($tempDirectory);
// -----------------------------------------------------------------------------
// Generate temporary documents
$tempFilenames = array();
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$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', Date::now()->toString(Date::DATE_LONG))->assign('time', Date::now()->toString(Date::TIME_LONG))->assign('city', randomString())->assign('country', randomString());
    $mailMerge->createDocument();
    file_put_contents($tempFilename, $mailMerge->retrieveDocument('pdf'));
    $logger->log(sprintf('Generating temporary document %s.', $tempFilename), Logger::INFO);
}
unset($mailMerge);
// -----------------------------------------------------------------------------
// Concatenate temporary documents and write output document
$outputFilename = __DIR__ . DIRECTORY_SEPARATOR . 'document-concat.pdf';
$logger->log('Concatenating temporary documents...', Logger::INFO);
if (true === concatenatePdfFilenames($tempFilenames, $outputFilename, $processor)) {
    $logger->log(sprintf('...DONE. Saved output document as %s.', basename($outputFilename)), Logger::INFO);
} else {
    $logger->log(sprintf('...ERROR.'), Logger::ERR);
}
// -----------------------------------------------------------------------------
コード例 #5
0
ファイル: generate-document.php プロジェクト: alab1001101/zf2
<?php

require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Date\Date;
use Zend\Service\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$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', Date::now()->toString(Date::DATE_LONG))->assign('time', Date::now()->toString(Date::TIME_LONG))->assign('city', 'Berlin')->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::now()->toString(Date::DATE_LONG),
        'time'     => Date::now()->toString(Date::TIME_LONG),
        'city'     => 'Berlin',
コード例 #6
0
ファイル: DateTest.php プロジェクト: rikaix/zf2
 /**
  * Test accessors for _Locale member property of Zend_Date
  */
 public function testLocale()
 {
     $date = new Date(Date::now());
     $locale = new Locale('en_US');
     $date->setLocale($locale);
     $this->assertSame('en_US', $date->getLocale());
 }
コード例 #7
0
ファイル: generate-document.php プロジェクト: alab1001101/zf2
<?php

require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Date\Date;
use Zend\Service\LiveDocx\Helper;
use Zend\Service\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
/*
 * ALTERNATIVE: Specify username and password in constructor
 */
/*
$mailMerge = new MailMerge(
    array (
        'username' => DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME,
        'password' => DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD
    )
);
*/
$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' => Date::now()->toString(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::now()->toString(Date::MONTH_NAME), Date::now()->toString(Date::YEAR)), '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);
コード例 #8
0
<?php

require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Date\Date;
use Zend\Service\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
/**
 * Image Source:
 * iStock_000003413016Medium_business-man-with-hands-up.jpg
 */
$photoFilename = 'dailemaitre.jpg';
if (!$mailMerge->imageExists($photoFilename)) {
    $mailMerge->uploadImage($photoFilename);
}
$mailMerge->setLocalTemplate('template.docx');
$mailMerge->assign('name', 'Daï Lemaitre')->assign('company', 'Megasoft Co-operation')->assign('date', Date::now()->toString(Date::DATE_LONG))->assign('image:photo', $photoFilename);
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
$mailMerge->deleteImage($photoFilename);
unset($mailMerge);