Zend_Service_LiveDocx.xml 35 KB

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