Zend_Service_LiveDocx.xml 36 KB

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