generate-document.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. require_once dirname(__FILE__) . '/../../common.php';
  3. $mailMerge = new Zend_Service_LiveDocx_MailMerge();
  4. $mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
  5. ->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
  6. $mailMerge->setLocalTemplate('template.docx');
  7. $mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9')
  8. ->assign('licensee', 'Henry Döner-Meyer')
  9. ->assign('company', 'Co-Operation')
  10. ->assign('date', Zend_Date::now()->toString(Zend_Date::DATE_LONG))
  11. ->assign('time', Zend_Date::now()->toString(Zend_Date::TIME_LONG))
  12. ->assign('city', 'Berlin')
  13. ->assign('country', 'Germany');
  14. /**
  15. * ALTERNATIVE: Concatenating PDF files locally - basic
  16. *
  17. * You can also assign multiple sets of data. In this case, each set of data
  18. * will populate the template and the resulting document (one per set of data)
  19. * will be appended to the previous document. Thus, in this example, we create
  20. * two documents that are concatenated into one PDF file.
  21. *
  22. * NOTE: In the case that you wish to generate several thousand documents that
  23. * are concatenated into one PDF, please take a look at the sample
  24. * application 'generate-document-pdftk.php' in this directory.
  25. */
  26. /*
  27. $fieldValues = array (
  28. // set 1
  29. array (
  30. 'software' => 'Magic Graphical Compression Suite v2.5',
  31. 'licensee' => 'Henry Döner-Meyer',
  32. 'company' => 'Megasoft Co-Operation',
  33. 'date' => Zend_Date::now()->toString(Zend_Date::DATE_LONG),
  34. 'time' => Zend_Date::now()->toString(Zend_Date::TIME_LONG),
  35. 'city' => 'Berlin',
  36. 'country' => 'Germany'
  37. ),
  38. // set 2
  39. array (
  40. 'software' => 'Magic CAD Suite v1.9',
  41. 'licensee' => 'Brüno Döner-Meyer',
  42. 'company' => 'Future Co-Operation',
  43. 'date' => Zend_Date::now()->toString(Zend_Date::DATE_LONG),
  44. 'time' => Zend_Date::now()->toString(Zend_Date::TIME_LONG),
  45. 'city' => 'Berlin',
  46. 'country' => 'Germany'
  47. )
  48. );
  49. $mailMerge->assign($fieldValues);
  50. */
  51. $mailMerge->createDocument();
  52. $document = $mailMerge->retrieveDocument('pdf');
  53. file_put_contents('document.pdf', $document);
  54. /*
  55. * ALTERNATIVE: Retrieve document in all supported formats
  56. *
  57. * You can also retrieve the document in all supported formats. In this case,
  58. * the generated document is written to the file system multiple times (one file
  59. * per format). This is only for exemplary purposes. In a real-world
  60. * application, you would probably decide on one or the other format.
  61. */
  62. /*
  63. foreach ($mailMerge->getDocumentFormats() as $format) {
  64. $document = $mailMerge->retrieveDocument($format);
  65. file_put_contents('document.' . $format, $document);
  66. }
  67. */
  68. unset($mailMerge);