Zend_Service_LiveDocx.xml 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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 <acronym>API</acronym>, it
  78. is important that 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.imageimport">
  182. <title>Image File Formats (import):</title>
  183. <para>
  184. Images can be merged into templates in any of following file 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. </itemizedlist>
  220. </sect4>
  221. <sect4 id="zend.service.livedocx.formats.imageexport">
  222. <title>Image File Formats (output):</title>
  223. <para>
  224. The resulting document can be exported to any of the following graphical file
  225. formats:
  226. </para>
  227. <itemizedlist>
  228. <listitem>
  229. <para>
  230. <ulink url="http://en.wikipedia.org/wiki/BMP_file_format">BMP</ulink> -
  231. Bitmap image format
  232. </para>
  233. </listitem>
  234. <listitem>
  235. <para>
  236. <ulink url="http://en.wikipedia.org/wiki/GIF">GIF</ulink> - Graphics
  237. Interchange Format
  238. </para>
  239. </listitem>
  240. <listitem>
  241. <para>
  242. <ulink url="http://en.wikipedia.org/wiki/Jpg">JPG</ulink> - Joint
  243. Photographic Experts Group format
  244. </para>
  245. </listitem>
  246. <listitem>
  247. <para>
  248. <ulink
  249. url="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</ulink>
  250. - Portable Network Graphics format
  251. </para>
  252. </listitem>
  253. <listitem>
  254. <para>
  255. <ulink
  256. url="http://en.wikipedia.org/wiki/Tagged_Image_File_Format">TIFF</ulink>
  257. - Tagged Image File Format
  258. </para>
  259. </listitem>
  260. <listitem>
  261. <para>
  262. <ulink url="http://en.wikipedia.org/wiki/Windows_Metafile">WMF</ulink> -
  263. Windows Meta File format
  264. </para>
  265. </listitem>
  266. </itemizedlist>
  267. </sect4>
  268. </sect3>
  269. </sect2>
  270. <sect2 id="zend.service.livedocx.mailmerge">
  271. <title>Zend_Service_LiveDocx_MailMerge</title>
  272. <para>
  273. <classname>Zend_Service_LiveDocx_MailMerge</classname> is the mail-merge object in the
  274. <classname>Zend_Service_LiveDocx</classname> family.
  275. </para>
  276. <sect3 id="zend.service.livedocx.mailmerge.generation">
  277. <title>Document Generation Process</title>
  278. <para>
  279. The document generation process can be simplified with the following equation:
  280. </para>
  281. <para>
  282. <emphasis>Template + Data = Document</emphasis>
  283. </para>
  284. <para>
  285. Or expressed by the following diagram:
  286. </para>
  287. <para>
  288. <inlinegraphic
  289. fileref="figures/zend.service.livedocx.mailmerge.generation-diabasic_zoom.png"
  290. format="PNG" />
  291. </para>
  292. <para>
  293. Data is inserted into template to create a document.
  294. </para>
  295. <para>
  296. A template, created in a word processing application, such as Microsoft Word, is
  297. loaded into LiveDocx. Data is then inserted into the template and the resulting
  298. document is saved to any supported format.
  299. </para>
  300. </sect3>
  301. <sect3 id="zend.service.livedocx.mailmerge.templates">
  302. <title>Creating Templates in Microsoft Word 2007</title>
  303. <para>
  304. Start off by launching Microsoft Word and creating a new document. Next, open up the
  305. <emphasis>Field</emphasis> dialog box. This looks as follows:
  306. </para>
  307. <para>
  308. <inlinegraphic
  309. fileref="figures/zend.service.livedocx.mailmerge.templates-msworddialog_zoom.png"
  310. format="PNG" />
  311. </para>
  312. <para>
  313. Microsoft Word 2007 Field dialog box.
  314. </para>
  315. <para>
  316. Using this dialog, you can insert the required merge fields into your document.
  317. Below is a screenshot of a license agreement in Microsoft Word 2007. The merge
  318. fields are marked as <command>{ MERGEFIELD FieldName }</command>:
  319. </para>
  320. <para>
  321. <inlinegraphic
  322. fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatefull_zoom.png"
  323. format="PNG" />
  324. </para>
  325. <para>
  326. Template in Microsoft Word 2007.
  327. </para>
  328. <para>
  329. Now, save the template as <emphasis>template.docx</emphasis>.
  330. </para>
  331. <para>
  332. In the next step, we are going to populate the merge fields with textual data from
  333. <acronym>PHP</acronym>.
  334. </para>
  335. <para>
  336. <inlinegraphic
  337. fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatecropped_zoom.png"
  338. format="PNG" />
  339. </para>
  340. <para>
  341. Cropped template in Microsoft Word 2007.
  342. </para>
  343. <para>
  344. To populate the merge fields in the above cropped screenshot of the <ulink
  345. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-template.docx">template</ulink>
  346. in Microsoft Word, all we have to code is as follows:
  347. </para>
  348. <programlisting language="php"><![CDATA[
  349. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  350. $phpLiveDocx->setUsername('myUsername')
  351. ->setPassword('myPassword');
  352. $phpLiveDocx->setLocalTemplate('template.docx');
  353. $phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
  354. ->assign('licensee', 'Henry Döner-Meyer')
  355. ->assign('company', 'Co-Operation');
  356. $phpLiveDocx->createDocument();
  357. $document = $phpLiveDocx->retrieveDocument('pdf');
  358. file_put_contents('document.pdf', $document);
  359. ]]></programlisting>
  360. <para>
  361. The resulting document is written to disk in the file
  362. <emphasis>document.pdf</emphasis>. This file can now be post-processed, sent via
  363. e-mail or simply displayed, as is illustrated below in <emphasis>Document Viewer
  364. 2.26.1</emphasis> on <emphasis>Ubuntu 9.04</emphasis>:
  365. </para>
  366. <para>
  367. <inlinegraphic
  368. fileref="figures/zend.service.livedocx.mailmerge.templates-msworddocument_zoom.png"
  369. format="PNG" />
  370. </para>
  371. <para>
  372. Resulting document as <acronym>PDF</acronym> in Document Viewer 2.26.1.
  373. </para>
  374. </sect3>
  375. <sect3 id="zend.service.livedocx.mailmerge.imagemerge">
  376. <title>Merging image data</title>
  377. <para>
  378. Using <classname>Zend_Service_LiveDocx_MailMerge</classname> it is also possible to merge images into
  379. a template. This feature is useful, for example, in the case of a badge application
  380. for a conference. In addition to the name and company name that should appear on
  381. the badge, it is possible to insert a photo of the delegate, using the API.
  382. </para>
  383. <para>
  384. Even it is sounds a little counter-intuitive, image-merging also work with
  385. text fields, as described in the section above. In fact, inserting a text field
  386. for an image is identical to inserting a text field for textual information.
  387. The only difference is the naming convention of the text field. Whereas, a text
  388. field for textual information can have (almost) any identifier, a text field for
  389. an image must start with <emphasis>image:</emphasis>. For example, in the case of our badge
  390. application, we would have the following 3 fields:
  391. </para>
  392. <para>
  393. <inlinegraphic
  394. fileref="figures/zend.service.livedocx.mailmerge.templates-imagemerge_zoom.png"
  395. format="PNG" />
  396. </para>
  397. <para>
  398. The text field, into which image data will be inserted is called <emphasis>image:photo</emphasis>
  399. and can be populated just like any other text field, using the assign method. The
  400. text fields <emphasis>name</emphasis> and <emphasis>company</emphasis> are regular
  401. text fields for textual information.
  402. </para>
  403. <para>
  404. Before we insert graphic data, we first have to upload the image to the backend
  405. LiveDocx server. This can be achieved using the <emphasis>uploadImage($filename)</emphasis> method.
  406. </para>
  407. <para>The following code snippet illustrates the flow:</para>
  408. <programlisting language="php"><![CDATA[
  409. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  410. $phpLiveDocx->setUsername('username')
  411. ->setPassword('password');
  412. $photoFilename = 'dailemaitre.jpg';
  413. if (!$phpLiveDocx->imageExists($photoFilename)) {
  414. $phpLiveDocx->uploadImage($photoFilename);
  415. }
  416. $phpLiveDocx->setLocalTemplate('template.docx');
  417. $phpLiveDocx->assign('name', 'Daï Lemaitre')
  418. ->assign('company', 'Megasoft Co-operation')
  419. ->assign('date', Zend_Date::now()->toString(Zend_Date::DATE_LONG))
  420. ->assign('image:photo', $photoFilename);
  421. $phpLiveDocx->createDocument();
  422. $document = $phpLiveDocx->retrieveDocument('pdf');
  423. file_put_contents('document.pdf', $document);
  424. $phpLiveDocx->deleteImage($photoFilename);
  425. ]]></programlisting>
  426. <para>
  427. Note that all images uploaded to your LiveDocx account must have a unique
  428. filename. In the case that you only intend to use the image once (such
  429. as is probable for our badge application), it makes sense to immediately
  430. delete it from the backend, using the <emphasis>deleteImage($filename)</emphasis> method.
  431. </para>
  432. </sect3>
  433. <sect3 id="zend.service.livedocx.mailmerge.advanced">
  434. <title>Advanced Mail-Merge</title>
  435. <para>
  436. <classname>Zend_Service_LiveDocx_MailMerge</classname> allows designers to insert
  437. any number of text fields into a template. These text fields are populated with data
  438. when <emphasis>createDocument()</emphasis> is called.
  439. </para>
  440. <para>
  441. In addition to text fields, it is also possible specify regions of a document, which
  442. should be repeated.
  443. </para>
  444. <para>
  445. For example, in a telephone bill it is necessary to print out a list of all
  446. connections, including the destination number, duration and cost of each call. This
  447. repeating row functionality can be achieved with so called blocks.
  448. </para>
  449. <para>
  450. <emphasis>Blocks</emphasis> are simply regions of a document, which are repeated
  451. when <methodname>createDocument()</methodname> is called. In a block any number of
  452. <emphasis>block fields</emphasis> can be specified.
  453. </para>
  454. <para>
  455. Blocks consist of two consecutive document targets with a unique name. The following
  456. screenshot illustrates these targets and their names in red:
  457. </para>
  458. <para>
  459. <inlinegraphic
  460. fileref="figures/zend.service.livedocx.mailmerge.advanced-mergefieldblockformat_zoom.png"
  461. format="PNG" />
  462. </para>
  463. <para>
  464. The format of a block is as follows:
  465. </para>
  466. <programlisting language="text"><![CDATA[
  467. blockStart_ + unique name
  468. blockEnd_ + unique name
  469. ]]></programlisting>
  470. <para>For example:</para>
  471. <programlisting language="text"><![CDATA[
  472. blockStart_block1
  473. blockEnd_block1
  474. ]]></programlisting>
  475. <para>
  476. The content of a block is repeated, until all data assigned in the block fields has
  477. been injected into the template. The data for block fields is specified in
  478. <acronym>PHP</acronym> as a multi-assoc array.
  479. </para>
  480. <para>
  481. The following screenshot of a template in Microsoft Word 2007 shows how block fields
  482. are used:
  483. </para>
  484. <para>
  485. <inlinegraphic
  486. fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblockstemplate_zoom.png"
  487. format="PNG" />
  488. </para>
  489. <para>
  490. Template, illustrating blocks in Microsoft Word 2007.
  491. </para>
  492. <para>
  493. The following code populates the above template with data.
  494. </para>
  495. <programlisting language="php"><![CDATA[
  496. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  497. $phpLiveDocx->setUsername('myUsername')
  498. ->setPassword('myPassword');
  499. $phpLiveDocx->setLocalTemplate('template.doc');
  500. $billConnections = array(
  501. array(
  502. 'connection_number' => '+49 421 335 912',
  503. 'connection_duration' => '00:00:07',
  504. 'fee' => '€ 0.03',
  505. ),
  506. array(
  507. 'connection_number' => '+49 421 335 913',
  508. 'connection_duration' => '00:00:07',
  509. 'fee' => '€ 0.03',
  510. ),
  511. array(
  512. 'connection_number' => '+49 421 335 914',
  513. 'connection_duration' => '00:00:07',
  514. 'fee' => '€ 0.03',
  515. ),
  516. array(
  517. 'connection_number' => '+49 421 335 916',
  518. 'connection_duration' => '00:00:07',
  519. 'fee' => '€ 0.03',
  520. ),
  521. );
  522. $phpLiveDocx->assign('connection', $billConnections);
  523. // ... assign other data here ...
  524. $phpLiveDocx->createDocument();
  525. $document = $phpLiveDocx->retrieveDocument('pdf');
  526. file_put_contents('document.pdf', $document);
  527. ]]></programlisting>
  528. <para>
  529. The data, which is specified in the array <varname>$billConnections</varname> is
  530. repeated in the template in the block connection. The keys of the array
  531. (<varname>connection_number</varname>, <varname>connection_duration</varname> and
  532. <varname>fee</varname>) are the block field names - their data is inserted, one row
  533. per iteration.
  534. </para>
  535. <para>
  536. The resulting document is written to disk in the file
  537. <emphasis>document.pdf</emphasis>. This file can now be post-processed, sent via
  538. e-mail or simply displayed, as is illustrated below in <emphasis>Document Viewer
  539. 2.26.1</emphasis> on <emphasis>Ubuntu 9.04</emphasis>:
  540. </para>
  541. <para>
  542. <inlinegraphic
  543. fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblocksdocument_zoom.png"
  544. format="PNG" />
  545. </para>
  546. <para>
  547. Resulting document as <acronym>PDF</acronym> in Document Viewer 2.26.1.
  548. </para>
  549. <para>
  550. You can download the <acronym>DOC</acronym> <ulink
  551. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-template.doc">template
  552. file</ulink> and the resulting <ulink
  553. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-document.pdf">PDF
  554. document</ulink>.
  555. </para>
  556. <para>
  557. <emphasis>NOTE:</emphasis> blocks may not be nested.
  558. </para>
  559. </sect3>
  560. <sect3 id="zend.service.livedocx.mailmerge.bitmaps">
  561. <title>Generating bitmaps image files</title>
  562. <para>
  563. In addition to document file formats,
  564. <classname>Zend_Service_LiveDocx_MailMerge</classname> also allows documents to be
  565. exported to a number of image file formats (<acronym>BMP</acronym>,
  566. <acronym>GIF</acronym>, <acronym>JPG</acronym>, <acronym>PNG</acronym> and
  567. <acronym>TIFF</acronym>). Each page of the document is saved to one file.
  568. </para>
  569. <para>
  570. The following sample illustrates the use of <methodname>getBitmaps($fromPage,
  571. $toPage, $zoomFactor, $format)</methodname> and
  572. <methodname>getAllBitmaps($zoomFactor, $format)</methodname>.
  573. </para>
  574. <para>
  575. <varname>$fromPage</varname> is the lower-bound page number of the page range that
  576. should be returned as an image and <varname>$toPage</varname> the upper-bound page
  577. number. <varname>$zoomFactor</varname> is the size of the images, as a percent,
  578. relative to the original page size. The range of this parameter is 10 to 400.
  579. <varname>$format</varname> is the format of the images returned by this method. The
  580. supported formats can be obtained by calling
  581. <methodname>getImageExportFormats()</methodname>.
  582. </para>
  583. <programlisting language="php"><![CDATA[
  584. $date = new Zend_Date();
  585. $date->setLocale('en_US');
  586. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  587. $phpLiveDocx->setUsername('myUsername')
  588. ->setPassword('myPassword');
  589. $phpLiveDocx->setLocalTemplate('template.docx');
  590. $phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
  591. ->assign('licensee', 'Daï Lemaitre')
  592. ->assign('company', 'Megasoft Co-operation')
  593. ->assign('date', $date->get(Zend_Date::DATE_LONG))
  594. ->assign('time', $date->get(Zend_Date::TIME_LONG))
  595. ->assign('city', 'Lyon')
  596. ->assign('country', 'France');
  597. $phpLiveDocx->createDocument();
  598. // Get all bitmaps
  599. // (zoomFactor, format)
  600. $bitmaps = $phpLiveDocx->getAllBitmaps(100, 'png');
  601. // Get just bitmaps in specified range
  602. // (fromPage, toPage, zoomFactor, format)
  603. // $bitmaps = $phpLiveDocx->getBitmaps(2, 2, 100, 'png');
  604. foreach ($bitmaps as $pageNumber => $bitmapData) {
  605. $filename = sprintf('documentPage%d.png', $pageNumber);
  606. file_put_contents($filename, $bitmapData);
  607. }
  608. ]]></programlisting>
  609. <para>
  610. This produces two files (<filename>documentPage1.png</filename> and
  611. <filename>documentPage2.png</filename>) and writes them to disk in the same
  612. directory as the executable <acronym>PHP</acronym> file.
  613. </para>
  614. <para>
  615. <inlinegraphic
  616. fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage1_zoom.png"
  617. format="PNG" />
  618. </para>
  619. <para>
  620. documentPage1.png.
  621. </para>
  622. <para>
  623. <inlinegraphic
  624. fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage2_zoom.png"
  625. format="PNG" />
  626. </para>
  627. <para>
  628. documentPage2.png.
  629. </para>
  630. </sect3>
  631. <sect3 id="zend.service.livedocx.mailmerge.templates-types">
  632. <title>Local vs. Remote Templates</title>
  633. <para>
  634. Templates can be stored <emphasis>locally</emphasis>, on the client machine, or
  635. <emphasis>remotely</emphasis>, on the server. There are advantages and disadvantages
  636. to each approach.
  637. </para>
  638. <para>
  639. In the case that a template is stored locally, it must be transfered from the client
  640. to the server on every request. If the content of the template rarely changes, this
  641. approach is inefficient. Similarly, if the template is several megabytes in size, it
  642. may take considerable time to transfer it to the server. Local template are useful
  643. in situations in which the content of the template is constantly changing.
  644. </para>
  645. <para>
  646. The following code illustrates how to use a local template.
  647. </para>
  648. <programlisting language="php"><![CDATA[
  649. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  650. $phpLiveDocx->setUsername('myUsername')
  651. ->setPassword('myPassword');
  652. $phpLiveDocx->setLocalTemplate('./template.docx');
  653. // assign data and create document
  654. ]]></programlisting>
  655. <para>
  656. In the case that a template is stored remotely, it is uploaded once to the server
  657. and then simply referenced on all subsequent requests. Obviously, this is much
  658. quicker than using a local template, as the template does not have to be transfered
  659. on every request. For speed critical applications, it is recommended to use the
  660. remote template method.
  661. </para>
  662. <para>
  663. The following code illustrates how to upload a template to the server:
  664. </para>
  665. <programlisting language="php"><![CDATA[
  666. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  667. $phpLiveDocx->setUsername('myUsername')
  668. ->setPassword('myPassword');
  669. $phpLiveDocx->uploadTemplate('template.docx');
  670. ]]></programlisting>
  671. <para>
  672. The following code illustrates how to reference the remotely stored template on all
  673. subsequent requests:
  674. </para>
  675. <programlisting language="php"><![CDATA[
  676. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  677. $phpLiveDocx->setUsername('myUsername')
  678. ->setPassword('myPassword');
  679. $phpLiveDocx->setRemoteTemplate('template.docx');
  680. // assign data and create document
  681. ]]></programlisting>
  682. </sect3>
  683. <sect3 id="zend.service.livedocx.mailmerge.information">
  684. <title>Getting Information</title>
  685. <para>
  686. <classname>Zend_Service_LiveDocx_MailMerge</classname> provides a number of methods
  687. to get information on field names, available fonts and supported formats.
  688. </para>
  689. <example id="zend.service.livedocx.mailmerge.information.getfieldname">
  690. <title>Get Array of Field Names in Template</title>
  691. <para>
  692. The following code returns and displays an array of all field names in the
  693. specified template. This functionality is useful, in the case that you create an
  694. application, in which an end-user can update a template.
  695. </para>
  696. <programlisting language="php"><![CDATA[
  697. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  698. $phpLiveDocx->setUsername('myUsername')
  699. ->setPassword('myPassword');
  700. $templateName = 'template-1-text-field.docx';
  701. $phpLiveDocx->setLocalTemplate($templateName);
  702. $fieldNames = $phpLiveDocx->getFieldNames();
  703. foreach ($fieldNames as $fieldName) {
  704. printf('- %s%s', $fieldName, PHP_EOL);
  705. }
  706. ]]></programlisting>
  707. </example>
  708. <example id="zend.service.livedocx.mailmerge.information.getblockfieldname">
  709. <title>Get Array of Block Field Names in Template</title>
  710. <para>
  711. The following code returns and displays an array of all block field names in the
  712. specified template. This functionality is useful, in the case that you create an
  713. application, in which an end-user can update a template. Before such templates
  714. can be populated, it is necessary to find out the names of the contained block
  715. fields.
  716. </para>
  717. <programlisting language="php"><![CDATA[
  718. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  719. $phpLiveDocx->setUsername('myUsername')
  720. ->setPassword('myPassword');
  721. $templateName = 'template-block-fields.doc';
  722. $phpLiveDocx->setLocalTemplate($templateName);
  723. $blockNames = $phpLiveDocx->getBlockNames();
  724. foreach ($blockNames as $blockName) {
  725. $blockFieldNames = $phpLiveDocx->getBlockFieldNames($blockName);
  726. foreach ($blockFieldNames as $blockFieldName) {
  727. printf('- %s::%s%s', $blockName, $blockFieldName, PHP_EOL);
  728. }
  729. }
  730. ]]></programlisting>
  731. </example>
  732. <example id="zend.service.livedocx.mailmerge.information.getfontnames">
  733. <title>Get Array of Fonts Installed on Server</title>
  734. <para>
  735. The following code returns and displays an array of all fonts installed on the
  736. server. You can use this method to present a list of fonts which may be used in
  737. a template. It is important to inform the end-user about the fonts installed on
  738. the server, as only these fonts may be used in a template. In the case that a
  739. template contains fonts, which are not available on the server,
  740. font-substitution will take place. This may lead to undesirable results.
  741. </para>
  742. <programlisting language="php"><![CDATA[
  743. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  744. $phpLiveDocx->setUsername('myUsername')
  745. ->setPassword('myPassword');
  746. Zend_Debug::dump($phpLiveDocx->getFontNames());
  747. ]]></programlisting>
  748. <para>
  749. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  750. infrequently, it is highly recommended to use a cache, such as
  751. <classname>Zend_Cache</classname> - this will considerably speed up your
  752. application.
  753. </para>
  754. </example>
  755. <example id="zend.service.livedocx.mailmerge.information.gettemplateformats">
  756. <title>Get Array of Supported Template File Formats</title>
  757. <para>
  758. The following code returns and displays an array of all supported template file
  759. formats. This method is particularly useful in the case that a combo list should
  760. be displayed that allows the end-user to select the input format of the
  761. documentation generation process.
  762. </para>
  763. <programlisting language="php"><![CDATA[
  764. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge()
  765. $phpLiveDocx->setUsername('myUsername')
  766. ->setPassword('myPassword');
  767. Zend_Debug::dump($phpLiveDocx->getTemplateFormats());
  768. ]]></programlisting>
  769. <para>
  770. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  771. infrequently, it is highly recommended to use a cache, such as
  772. <classname>Zend_Cache</classname> - this will considerably speed up your
  773. application.
  774. </para>
  775. </example>
  776. <example id="zend.service.livedocx.mailmerge.information.getdocumentformats">
  777. <title>Get Array of Supported Document File Formats</title>
  778. <para>
  779. The following code returns and displays an array of all supported document file
  780. formats. This method is particularly useful in the case that a combo list should
  781. be displayed that allows the end-user to select the output format of the
  782. documentation generation process.
  783. </para>
  784. <programlisting language="php"><![CDATA[
  785. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  786. $phpLiveDocx->setUsername('myUsername')
  787. ->setPassword('myPassword');
  788. Zend_Debug::dump($phpLiveDocx->getDocumentFormats());
  789. ]]></programlisting>
  790. </example>
  791. <example id="zend.service.livedocx.mailmerge.information.getimageimportformats">
  792. <title>Get Array of Supported Image Import File Formats</title>
  793. <para>
  794. The following code returns and displays an array of all supported imput image file
  795. formats.
  796. </para>
  797. <programlisting language="php"><![CDATA[
  798. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  799. $phpLiveDocx->setUsername('myUsername')
  800. ->setPassword('myPassword');
  801. Zend_Debug::dump($phpLiveDocx->getImageImportFormats());
  802. ]]></programlisting>
  803. <para>
  804. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  805. infrequently, it is highly recommended to use a cache, such as
  806. <classname>Zend_Cache</classname> - this will considerably speed up your
  807. application.
  808. </para>
  809. </example>
  810. <example id="zend.service.livedocx.mailmerge.information.getimageexportformats">
  811. <title>Get Array of Supported Image Export File Formats</title>
  812. <para>
  813. The following code returns and displays an array of all supported export image file
  814. formats. This method is particularly useful in the case that a combo list should
  815. be displayed that allows the end-user to select the output format of the
  816. documentation generation process.
  817. </para>
  818. <programlisting language="php"><![CDATA[
  819. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  820. $phpLiveDocx->setUsername('myUsername')
  821. ->setPassword('myPassword');
  822. Zend_Debug::dump($phpLiveDocx->getImageExportFormats());
  823. ]]></programlisting>
  824. <para>
  825. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  826. infrequently, it is highly recommended to use a cache, such as
  827. <classname>Zend_Cache</classname> - this will considerably speed up your
  828. application.
  829. </para>
  830. </example>
  831. </sect3>
  832. </sect2>
  833. </sect1>
  834. <!--
  835. vim:se ts=4 sw=4 tw=100 et:
  836. -->