<?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);
} $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.')); } // ----------------------------------------------------------------------------- // Delete temporary directory $logger->log(Logger::INFO, sprintf('Deleting temporary directory %s.', $tempDirectory));
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 $item->save(); case 'item.update':