} $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'); $date = new DateTime(); 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->format('Y-m-d'))->assign('time', $date->format('H:i:s'))->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); } // ----------------------------------------------------------------------------- // Delete temporary directory $logger->log(sprintf('Deleting temporary directory %s.', $tempDirectory), Logger::INFO);
// set 2 array ( 'software' => 'Magic CAD Suite v1.9', 'licensee' => 'Brüno Döner-Meyer', 'company' => 'Future Co-Operation', 'date' => Date::now()->toString(Date::DATE_LONG), 'time' => Date::now()->toString(Date::TIME_LONG), 'city' => 'Berlin', 'country' => 'Germany' ) ); $mailMerge->assign($fieldValues); */ $mailMerge->createDocument(); $document = $mailMerge->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 ($mailMerge->getDocumentFormats() as $format) { $document = $mailMerge->retrieveDocument($format); file_put_contents('document.' . $format, $document); } */