generate-document.php 3.1 KB

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