Zend_Service_LiveDocx.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.livedocx">
  4. <title>Zend_Service_LiveDocx</title>
  5. <sect2 id="zend.service.livedocx.introduction">
  6. <title>Introduction to LiveDocx</title>
  7. <para>
  8. LiveDocx is a <acronym>SOAP</acronym> service that allows developers to generate word
  9. processing documents by combining structured data from PHP with a template, created in a
  10. word processor. The resulting document can be saved as a <acronym>PDF</acronym>,
  11. <acronym>DOCX</acronym>, <acronym>DOC</acronym>, <acronym>HTML</acronym> or
  12. <acronym>RTF</acronym> file. LiveDocx implements <ulink
  13. url="http://en.wikipedia.org/wiki/Mail_merge">mail-merge</ulink> in PHP.
  14. </para>
  15. <para>
  16. The family of <classname>Zend_Service_LiveDocx</classname> components provides a clean
  17. and simple interface to the <ulink url="http://www.livedocx.com">LiveDocx API</ulink>
  18. and additionally offers functionality to improve network performance.
  19. </para>
  20. <para>
  21. In addition to this section of the manual, if you are interested in learning more about
  22. <classname>Zend_Service_LiveDocx</classname> and the backend <acronym>SOAP</acronym>
  23. service LiveDocx, please take a look at the following resources:
  24. </para>
  25. <itemizedlist>
  26. <listitem>
  27. <para>
  28. <emphasis>Shipped demonstration applications</emphasis>. There are a large
  29. number of demonstration applications in the directory
  30. <emphasis>/demos/Zend/Service/LiveDocx</emphasis> of the Zend Framework
  31. distribution file or trunk version, checked out of the standard SVN repository.
  32. These are designed to get you up to speed with
  33. <classname>Zend_Service_LiveDocx</classname> within a matter of minutes.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. <ulink url="http://www.phplivedocx.org/">
  39. <classname>Zend_Service_LiveDocx</classname> blog and web site</ulink>.
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>
  44. <ulink url="http://www.livedocx.com/pub/documentation/api.aspx">
  45. LiveDocx SOAP API documentation</ulink>.
  46. </para>
  47. </listitem>
  48. <listitem>
  49. <para>
  50. <ulink url="https://api.livedocx.com/1.2/mailmerge.asmx?wsdl">
  51. LiveDocx WSDL</ulink>.
  52. </para>
  53. </listitem>
  54. <listitem>
  55. <para>
  56. <ulink url="https://www.livedocx.com/">LiveDocx blog and web site</ulink>.
  57. </para>
  58. </listitem>
  59. </itemizedlist>
  60. <sect3 id="zend.service.livedocx.account">
  61. <title>Sign Up for an Account</title>
  62. <para>
  63. Before you can start using LiveDocx, you must first <ulink
  64. url="https://www.livedocx.com/user/account_registration.aspx">sign up</ulink>
  65. for an account. The account is completely free of charge and you only need to
  66. specify a <emphasis>username</emphasis>, <emphasis>password</emphasis> and
  67. <emphasis>e-mail address</emphasis>. Your login credentials will be dispatched to
  68. the e-mail address you supply, so please type carefully.
  69. </para>
  70. </sect3>
  71. <sect3 id="zend.service.livedocx.templates-documents">
  72. <title>Templates and Documents</title>
  73. <para>
  74. LiveDocx differentiates between the following terms: 1)
  75. <emphasis>template</emphasis> and 2) <emphasis>document</emphasis>. In order to
  76. fully understand the documentation and indeed the actual API, it is important that
  77. any programmer deploying LiveDocx understands the difference.
  78. </para>
  79. <para>
  80. The term <emphasis>template</emphasis> is used to refer to the input file, created
  81. in a word processor, containing formatting and text fields. You can download an
  82. <ulink
  83. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-template.docx">example
  84. template</ulink>, stored as a <acronym>DOCX</acronym> file. The term
  85. <emphasis>document</emphasis> is used to refer to the output file that contains the
  86. template file, populated with data - i.e. the finished document. You can download an
  87. <ulink
  88. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-document.pdf">example
  89. document</ulink>, stored as a <acronym>PDF</acronym> file.
  90. </para>
  91. </sect3>
  92. <sect3 id="zend.service.livedocx.formats">
  93. <title>Supported File Formats</title>
  94. <para>
  95. LiveDocx supports the following file formats:
  96. </para>
  97. <sect4 id="zend.service.livedocx.formats.template">
  98. <title>Template File Formats (input)</title>
  99. <para>
  100. Templates can be saved in any of the following file formats:
  101. </para>
  102. <itemizedlist>
  103. <listitem>
  104. <para>
  105. <ulink url="http://en.wikipedia.org/wiki/Office_Open_XML">DOCX</ulink> -
  106. Office Open <acronym>XML</acronym> format
  107. </para>
  108. </listitem>
  109. <listitem>
  110. <para>
  111. <ulink url="http://en.wikipedia.org/wiki/DOC_(computing)">DOC</ulink> -
  112. Microsoft Word <acronym>DOC</acronym> format
  113. </para>
  114. </listitem>
  115. <listitem>
  116. <para>
  117. <ulink url="http://en.wikipedia.org/wiki/Rich_Text_Format">RTF</ulink> -
  118. Rich text file format
  119. </para>
  120. </listitem>
  121. <listitem>
  122. <para>
  123. <ulink url="http://www.textcontrol.com/">TXD</ulink> - TX Text Control
  124. format
  125. </para>
  126. </listitem>
  127. </itemizedlist>
  128. </sect4>
  129. <sect4 id="zend.service.livedocx.formats.document">
  130. <title>Document File Formats (output):</title>
  131. <para>
  132. The resulting document can be saved in any of the following file formats:
  133. </para>
  134. <itemizedlist>
  135. <listitem>
  136. <para>
  137. <ulink url="http://en.wikipedia.org/wiki/Office_Open_XML">DOCX</ulink> -
  138. Office Open <acronym>XML</acronym> format
  139. </para>
  140. </listitem>
  141. <listitem>
  142. <para>
  143. <ulink url="http://en.wikipedia.org/wiki/DOC_(computing)">DOC</ulink> -
  144. Microsoft Word <acronym>DOC</acronym> format
  145. </para>
  146. </listitem>
  147. <listitem>
  148. <para>
  149. <ulink url="http://en.wikipedia.org/wiki/Xhtml">HTML</ulink> -
  150. <acronym>XHTML</acronym> 1.0 transitional format
  151. </para>
  152. </listitem>
  153. <listitem>
  154. <para>
  155. <ulink url="http://en.wikipedia.org/wiki/Rich_Text_Format">RTF</ulink> -
  156. Rich text file format
  157. </para>
  158. </listitem>
  159. <listitem>
  160. <para>
  161. <ulink
  162. url="http://en.wikipedia.org/wiki/Portable_Document_Format">PDF</ulink>
  163. - Acrobat Portable Document Format
  164. </para>
  165. </listitem>
  166. <listitem>
  167. <para>
  168. <ulink url="http://www.textcontrol.com/">TXD</ulink> - TX Text Control
  169. format
  170. </para>
  171. </listitem>
  172. <listitem>
  173. <para>
  174. <ulink url="http://en.wikipedia.org/wiki/Text_file">TXT</ulink> -
  175. <acronym>ANSI</acronym> plain text
  176. </para>
  177. </listitem>
  178. </itemizedlist>
  179. </sect4>
  180. <sect4 id="zend.service.livedocx.formats.image">
  181. <title>Image File Formats (output):</title>
  182. <para>
  183. The resulting document can be saved in any of the following graphical file
  184. formats:
  185. </para>
  186. <itemizedlist>
  187. <listitem>
  188. <para>
  189. <ulink url="http://en.wikipedia.org/wiki/BMP_file_format">BMP</ulink> -
  190. Bitmap image format
  191. </para>
  192. </listitem>
  193. <listitem>
  194. <para>
  195. <ulink url="http://en.wikipedia.org/wiki/GIF">GIF</ulink> - Graphics
  196. Interchange Format
  197. </para>
  198. </listitem>
  199. <listitem>
  200. <para>
  201. <ulink url="http://en.wikipedia.org/wiki/Jpg">JPG</ulink> - Joint
  202. Photographic Experts Group format
  203. </para>
  204. </listitem>
  205. <listitem>
  206. <para>
  207. <ulink
  208. url="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</ulink>
  209. - Portable Network Graphics format
  210. </para>
  211. </listitem>
  212. <listitem>
  213. <para>
  214. <ulink
  215. url="http://en.wikipedia.org/wiki/Tagged_Image_File_Format">TIFF</ulink>
  216. - Tagged Image File Format
  217. </para>
  218. </listitem>
  219. <listitem>
  220. <para>
  221. <ulink url="http://en.wikipedia.org/wiki/Windows_Metafile">WMF</ulink> -
  222. Windows Meta File format
  223. </para>
  224. </listitem>
  225. </itemizedlist>
  226. </sect4>
  227. </sect3>
  228. </sect2>
  229. <sect2 id="zend.service.livedocx.mailmerge">
  230. <title>Zend_Service_LiveDocx_MailMerge</title>
  231. <para>
  232. <classname>Zend_Service_LiveDocx_MailMerge</classname> is the mail-merge object in the
  233. <classname>Zend_Service_LiveDocx</classname> family.
  234. </para>
  235. <sect3 id="zend.service.livedocx.mailmerge.generation">
  236. <title>Document Generation Process</title>
  237. <para>
  238. The document generation process can be simplified with the following equation:
  239. </para>
  240. <para>
  241. <emphasis>Template + Data = Document</emphasis>
  242. </para>
  243. <para>
  244. Or expressed by the following diagram:
  245. </para>
  246. <para>
  247. <inlinegraphic
  248. fileref="figures/zend.service.livedocx.mailmerge.generation-diabasic_zoom.png"
  249. format="PNG" />
  250. </para>
  251. <para>
  252. Data is inserted into template to create a document.
  253. </para>
  254. <para>
  255. A template, created in a word processing application, such as Microsoft Word, is
  256. loaded into LiveDocx. Data is then inserted into the template and the resulting
  257. document is saved to any supported format.
  258. </para>
  259. </sect3>
  260. <sect3 id="zend.service.livedocx.mailmerge.templates">
  261. <title>Creating Templates in Microsoft Word 2007</title>
  262. <para>
  263. Start off by launching Microsoft Word and creating a new document. Next, open up the
  264. <emphasis>Field</emphasis> dialog box. This looks as follows:
  265. </para>
  266. <para>
  267. <inlinegraphic
  268. fileref="figures/zend.service.livedocx.mailmerge.templates-msworddialog_zoom.png"
  269. format="PNG" />
  270. </para>
  271. <para>
  272. Microsoft Word 2007 Field dialog box.
  273. </para>
  274. <para>
  275. Using this dialog, you can insert the required merge fields into your document.
  276. Below is a screenshot of a license agreement in Microsoft Word 2007. The merge
  277. fields are marked as <code>{ MERGEFIELD FieldName }</code>:
  278. </para>
  279. <para>
  280. <inlinegraphic
  281. fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatefull_zoom.png"
  282. format="PNG" />
  283. </para>
  284. <para>
  285. Template in Microsoft Word 2007.
  286. </para>
  287. <para>
  288. Now, save the template as <emphasis>template.docx</emphasis>.
  289. </para>
  290. <para>
  291. In the next step, we are going to populate the merge fields with textual data from
  292. PHP.
  293. </para>
  294. <para>
  295. <inlinegraphic
  296. fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatecropped_zoom.png"
  297. format="PNG" />
  298. </para>
  299. <para>
  300. Cropped template in Microsoft Word 2007.
  301. </para>
  302. <para>
  303. To populate the merge fields in the above cropped screenshot of the <ulink
  304. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-template.docx">template</ulink>
  305. in Microsoft Word, all we have to code is as follows:
  306. </para>
  307. <programlisting language="php"><![CDATA[
  308. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  309. $phpLiveDocx->setUsername('myUsername')
  310. ->setPassword('myPassword');
  311. $phpLiveDocx->setLocalTemplate('template.docx');
  312. $phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
  313. ->assign('licensee', 'Henry Döner-Meyer')
  314. ->assign('company', 'Co-Operation');
  315. $phpLiveDocx->createDocument();
  316. $document = $phpLiveDocx->retrieveDocument('pdf');
  317. file_put_contents('document.pdf', $document);
  318. ]]></programlisting>
  319. <para>
  320. The resulting document is written to disk in the file
  321. <emphasis>document.pdf</emphasis>. This file can now be post-processed, sent via
  322. e-mail or simply displayed, as is illustrated below in <emphasis>Document Viewer
  323. 2.26.1</emphasis> on <emphasis>Ubuntu 9.04</emphasis>:
  324. </para>
  325. <para>
  326. <inlinegraphic
  327. fileref="figures/zend.service.livedocx.mailmerge.templates-msworddocument_zoom.png"
  328. format="PNG" />
  329. </para>
  330. <para>
  331. Resulting document as <acronym>PDF</acronym> in Document Viewer 2.26.1.
  332. </para>
  333. </sect3>
  334. <sect3 id="zend.service.livedocx.mailmerge.advanced">
  335. <title>Advanced Mail-Merge</title>
  336. <para>
  337. <classname>Zend_Service_LiveDocx_MailMerge</classname> allows designers to insert
  338. any number of text fields into a template. These text fields are populated with data
  339. when <emphasis>createDocument()</emphasis> is called.
  340. </para>
  341. <para>
  342. In addition to text fields, it is also possible specify regions of a document, which
  343. should be repeated.
  344. </para>
  345. <para>
  346. For example, in a telephone bill it is necessary to print out a list of all
  347. connections, including the destination number, duration and cost of each call. This
  348. repeating row functionality can be achieved with so called blocks.
  349. </para>
  350. <para>
  351. <emphasis>Blocks</emphasis> are simply regions of a document, which are repeated
  352. when <methodname>createDocument()</methodname> is called. In a block any number of
  353. <emphasis>block fields</emphasis> can be specified.
  354. </para>
  355. <para>
  356. Blocks consist of two consecutive document targets with a unique name. The following
  357. screenshot illustrates these targets and their names in red:
  358. </para>
  359. <para>
  360. <inlinegraphic
  361. fileref="figures/zend.service.livedocx.mailmerge.advanced-mergefieldblockformat_zoom.png"
  362. format="PNG" />
  363. </para>
  364. <para>
  365. The format of a block is as follows:
  366. </para>
  367. <programlisting language="text"><![CDATA[
  368. blockStart_ + unique name
  369. blockEnd_ + unique name
  370. ]]></programlisting>
  371. <para>For example:</para>
  372. <programlisting language="text"><![CDATA[
  373. blockStart_block1
  374. blockEnd_block1
  375. ]]></programlisting>
  376. <para>
  377. The content of a block is repeated, until all data assigned in the block fields has
  378. been injected into the template. The data for block fields is specified in PHP as a
  379. multi-assoc array.
  380. </para>
  381. <para>
  382. The following screenshot of a template in Microsoft Word 2007 shows how block fields
  383. are used:
  384. </para>
  385. <para>
  386. <inlinegraphic
  387. fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblockstemplate_zoom.png"
  388. format="PNG" />
  389. </para>
  390. <para>
  391. Template, illustrating blocks in Microsoft Word 2007.
  392. </para>
  393. <para>
  394. The following code populates the above template with data.
  395. </para>
  396. <programlisting language="php"><![CDATA[
  397. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  398. $phpLiveDocx->setUsername('myUsername')
  399. ->setPassword('myPassword');
  400. $phpLiveDocx->setLocalTemplate('template.doc');
  401. $billConnections = array(
  402. array(
  403. 'connection_number' => '+49 421 335 912',
  404. 'connection_duration' => '00:00:07',
  405. 'fee' => '€ 0.03',
  406. ),
  407. array(
  408. 'connection_number' => '+49 421 335 913',
  409. 'connection_duration' => '00:00:07',
  410. 'fee' => '€ 0.03',
  411. ),
  412. array(
  413. 'connection_number' => '+49 421 335 914',
  414. 'connection_duration' => '00:00:07',
  415. 'fee' => '€ 0.03',
  416. ),
  417. array(
  418. 'connection_number' => '+49 421 335 916',
  419. 'connection_duration' => '00:00:07',
  420. 'fee' => '€ 0.03',
  421. ),
  422. );
  423. $phpLiveDocx->assign('connection', $billConnections);
  424. // ... assign other data here ...
  425. $phpLiveDocx->createDocument();
  426. $document = $phpLiveDocx->retrieveDocument('pdf');
  427. file_put_contents('document.pdf', $document);
  428. ]]></programlisting>
  429. <para>
  430. The data, which is specified in the array <varname>$billConnections</varname> is
  431. repeated in the template in the block connection. The keys of the array
  432. (<varname>connection_number</varname>, <varname>connection_duration</varname> and
  433. <varname>fee</varname>) are the block field names - their data is inserted, one row
  434. per iteration.
  435. </para>
  436. <para>
  437. The resulting document is written to disk in the file
  438. <emphasis>document.pdf</emphasis>. This file can now be post-processed, sent via
  439. e-mail or simply displayed, as is illustrated below in <emphasis>Document Viewer
  440. 2.26.1</emphasis> on <emphasis>Ubuntu 9.04</emphasis>:
  441. </para>
  442. <para>
  443. <inlinegraphic
  444. fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblocksdocument_zoom.png"
  445. format="PNG" />
  446. </para>
  447. <para>
  448. Resulting document as <acronym>PDF</acronym> in Document Viewer 2.26.1.
  449. </para>
  450. <para>
  451. You can download the <acronym>DOC</acronym> <ulink
  452. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-template.doc">template
  453. file</ulink> and the resulting <ulink
  454. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-document.pdf">PDF
  455. document</ulink>.
  456. </para>
  457. <para>
  458. <emphasis>NOTE:</emphasis> blocks may not be nested.
  459. </para>
  460. </sect3>
  461. <sect3 id="zend.service.livedocx.mailmerge.bitmaps">
  462. <title>Generating bitmaps image files</title>
  463. <para>
  464. In addition to document file formats,
  465. <classname>Zend_Service_LiveDocx_MailMerge</classname> also allows documents to be
  466. saved to a number of image file formats (<acronym>BMP</acronym>,
  467. <acronym>GIF</acronym>, <acronym>JPG</acronym>, <acronym>PNG</acronym> and
  468. <acronym>TIFF</acronym>). Each page of the document is saved to one file.
  469. </para>
  470. <para>
  471. The following sample illustrates the use of <methodname>getBitmaps($fromPage,
  472. $toPage, $zoomFactor, $format)</methodname> and
  473. <methodname>getAllBitmaps($zoomFactor, $format)</methodname>.
  474. </para>
  475. <para>
  476. <varname>$fromPage</varname> is the lower-bound page number of the page range that
  477. should be returned as an image and <varname>$toPage</varname> the upper-bound page
  478. number. <varname>$zoomFactor</varname> is the size of the images, as a percent,
  479. relative to the original page size. The range of this parameter is 10 to 400.
  480. <varname>$format</varname> is the format of the images returned by this method. The
  481. supported formats can be obtained by calling
  482. <methodname>getImageFormats()</methodname>.
  483. </para>
  484. <programlisting language="php"><![CDATA[
  485. $date = new Zend_Date();
  486. $date->setLocale('en_US');
  487. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  488. $phpLiveDocx->setUsername('myUsername')
  489. ->setPassword('myPassword');
  490. $phpLiveDocx->setLocalTemplate('template.docx');
  491. $phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
  492. ->assign('licensee', 'Daï Lemaitre')
  493. ->assign('company', 'Megasoft Co-operation')
  494. ->assign('date', $date->get(Zend_Date::DATE_LONG))
  495. ->assign('time', $date->get(Zend_Date::TIME_LONG))
  496. ->assign('city', 'Lyon')
  497. ->assign('country', 'France');
  498. $phpLiveDocx->createDocument();
  499. // Get all bitmaps
  500. // (zoomFactor, format)
  501. $bitmaps = $phpLiveDocx->getAllBitmaps(100, 'png');
  502. // Get just bitmaps in specified range
  503. // (fromPage, toPage, zoomFactor, format)
  504. // $bitmaps = $phpLiveDocx->getBitmaps(2, 2, 100, 'png');
  505. foreach ($bitmaps as $pageNumber => $bitmapData) {
  506. $filename = sprintf('documentPage%d.png', $pageNumber);
  507. file_put_contents($filename, $bitmapData);
  508. }
  509. ]]></programlisting>
  510. <para>
  511. This produces two files (<filename>documentPage1.png</filename> and
  512. <filename>documentPage2.png</filename>) and writes them to disk in the same
  513. directory as the executable PHP file.
  514. </para>
  515. <para>
  516. <inlinegraphic
  517. fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage1_zoom.png"
  518. format="PNG" />
  519. </para>
  520. <para>
  521. documentPage1.png.
  522. </para>
  523. <para>
  524. <inlinegraphic
  525. fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage2_zoom.png"
  526. format="PNG" />
  527. </para>
  528. <para>
  529. documentPage2.png.
  530. </para>
  531. </sect3>
  532. <sect3 id="zend.service.livedocx.mailmerge.templates-types">
  533. <title>Local vs. Remote Templates</title>
  534. <para>
  535. Templates can be stored <emphasis>locally</emphasis>, on the client machine, or
  536. <emphasis>remotely</emphasis>, on the server. There are advantages and disadvantages
  537. to each approach.
  538. </para>
  539. <para>
  540. In the case that a template is stored locally, it must be transfered from the client
  541. to the server on every request. If the content of the template rarely changes, this
  542. approach is inefficient. Similarly, if the template is several megabytes in size, it
  543. may take considerable time to transfer it to the server. Local template are useful
  544. in situations in which the content of the template is constantly changing.
  545. </para>
  546. <para>
  547. The following code illustrates how to use a local template.
  548. </para>
  549. <programlisting language="php"><![CDATA[
  550. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  551. $phpLiveDocx->setUsername('myUsername')
  552. ->setPassword('myPassword');
  553. $phpLiveDocx->setLocalTemplate('./template.docx');
  554. // assign data and create document
  555. ]]></programlisting>
  556. <para>
  557. In the case that a template is stored remotely, it is uploaded once to the server
  558. and then simply referenced on all subsequent requests. Obviously, this is much
  559. quicker than using a local template, as the template does not have to be transfered
  560. on every request. For speed critical applications, it is recommended to use the
  561. remote template method.
  562. </para>
  563. <para>
  564. The following code illustrates how to upload a template to the server:
  565. </para>
  566. <programlisting language="php"><![CDATA[
  567. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  568. $phpLiveDocx->setUsername('myUsername')
  569. ->setPassword('myPassword');
  570. $phpLiveDocx->uploadTemplate('template.docx');
  571. ]]></programlisting>
  572. <para>
  573. The following code illustrates how to reference the remotely stored template on all
  574. subsequent requests:
  575. </para>
  576. <programlisting language="php"><![CDATA[
  577. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  578. $phpLiveDocx->setUsername('myUsername')
  579. ->setPassword('myPassword');
  580. $phpLiveDocx->setRemoteTemplate('template.docx');
  581. // assign data and create document
  582. ]]></programlisting>
  583. </sect3>
  584. <sect3 id="zend.service.livedocx.mailmerge.information">
  585. <title>Getting Information</title>
  586. <para>
  587. <classname>Zend_Service_LiveDocx_MailMerge</classname> provides a number of methods
  588. to get information on field names, available fonts and supported formats.
  589. </para>
  590. <example id="zend.service.livedocx.mailmerge.information.getfieldname">
  591. <title>Get Array of Field Names in Template</title>
  592. <para>
  593. The following code returns and displays an array of all field names in the
  594. specified template. This functionality is useful, in the case that you create an
  595. application, in which an end-user can update a template.
  596. </para>
  597. <programlisting language="php"><![CDATA[
  598. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  599. $phpLiveDocx->setUsername('myUsername')
  600. ->setPassword('myPassword');
  601. $templateName = 'template-1-text-field.docx';
  602. $phpLiveDocx->setLocalTemplate($templateName);
  603. $fieldNames = $phpLiveDocx->getFieldNames();
  604. foreach ($fieldNames as $fieldName) {
  605. printf('- %s%s', $fieldName, PHP_EOL);
  606. }
  607. ]]></programlisting>
  608. </example>
  609. <example id="zend.service.livedocx.mailmerge.information.getblockfieldname">
  610. <title>Get Array of Block Field Names in Template</title>
  611. <para>
  612. The following code returns and displays an array of all block field names in the
  613. specified template. This functionality is useful, in the case that you create an
  614. application, in which an end-user can update a template. Before such templates
  615. can be populated, it is necessary to find out the names of the contained block
  616. fields.
  617. </para>
  618. <programlisting language="php"><![CDATA[
  619. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  620. $phpLiveDocx->setUsername('myUsername')
  621. ->setPassword('myPassword');
  622. $templateName = 'template-block-fields.doc';
  623. $phpLiveDocx->setLocalTemplate($templateName);
  624. $blockNames = $phpLiveDocx->getBlockNames();
  625. foreach ($blockNames as $blockName) {
  626. $blockFieldNames = $phpLiveDocx->getBlockFieldNames($blockName);
  627. foreach ($blockFieldNames as $blockFieldName) {
  628. printf('- %s::%s%s', $blockName, $blockFieldName, PHP_EOL);
  629. }
  630. }
  631. ]]></programlisting>
  632. </example>
  633. <example id="zend.service.livedocx.mailmerge.information.getfontnames">
  634. <title>Get Array of Fonts Installed on Server</title>
  635. <para>
  636. The following code returns and displays an array of all fonts installed on the
  637. server. You can use this method to present a list of fonts which may be used in
  638. a template. It is important to inform the end-user about the fonts installed on
  639. the server, as only these fonts may be used in a template. In the case that a
  640. template contains fonts, which are not available on the server,
  641. font-substitution will take place. This may lead to undesirable results.
  642. </para>
  643. <programlisting language="php"><![CDATA[
  644. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  645. $phpLiveDocx->setUsername('myUsername')
  646. ->setPassword('myPassword');
  647. Zend_Debug::dump($phpLiveDocx->getFontNames());
  648. ]]></programlisting>
  649. <para>
  650. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  651. infrequently, it is highly recommended to use a cache, such as
  652. <classname>Zend_Cache</classname> - this will considerably speed up your
  653. application.
  654. </para>
  655. </example>
  656. <example id="zend.service.livedocx.mailmerge.information.gettemplateformats">
  657. <title>Get Array of Supported Template File Formats</title>
  658. <para>
  659. The following code returns and displays an array of all supported template file
  660. formats. This method is particularly useful in the case that a combo list should
  661. be displayed that allows the end-user to select the input format of the
  662. documentation generation process.
  663. </para>
  664. <programlisting language="php"><![CDATA[
  665. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge()
  666. $phpLiveDocx->setUsername('myUsername')
  667. ->setPassword('myPassword');
  668. Zend_Debug::dump($phpLiveDocx->getTemplateFormats());
  669. ]]></programlisting>
  670. <para>
  671. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  672. infrequently, it is highly recommended to use a cache, such as
  673. <classname>Zend_Cache</classname> - this will considerably speed up your
  674. application.
  675. </para>
  676. </example>
  677. <example id="zend.service.livedocx.mailmerge.information.getdocumentformats">
  678. <title>Get Array of Supported Document File Formats</title>
  679. <para>
  680. The following code returns and displays an array of all supported document file
  681. formats. This method is particularly useful in the case that a combo list should
  682. be displayed that allows the end-user to select the output format of the
  683. documentation generation process.
  684. </para>
  685. <programlisting language="php"><![CDATA[
  686. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  687. $phpLiveDocx->setUsername('myUsername')
  688. ->setPassword('myPassword');
  689. Zend_Debug::dump($phpLiveDocx->getDocumentFormats());
  690. ]]></programlisting>
  691. </example>
  692. <example id="zend.service.livedocx.mailmerge.information.getimageformats">
  693. <title>Get Array of Supported Image File Formats</title>
  694. <para>
  695. The following code returns and displays an array of all supported image file
  696. formats. This method is particularly useful in the case that a combo list should
  697. be displayed that allows the end-user to select the output format of the
  698. documentation generation process.
  699. </para>
  700. <programlisting language="php"><![CDATA[
  701. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  702. $phpLiveDocx->setUsername('myUsername')
  703. ->setPassword('myPassword');
  704. Zend_Debug::dump($phpLiveDocx->getImageFormats());
  705. ]]></programlisting>
  706. <para>
  707. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  708. infrequently, it is highly recommended to use a cache, such as
  709. <classname>Zend_Cache</classname> - this will considerably speed up your
  710. application.
  711. </para>
  712. </example>
  713. </sect3>
  714. </sect2>
  715. </sect1>
  716. <!--
  717. vim:se ts=4 sw=4 tw=100 et:
  718. -->