Zend_Service_LiveDocx.xml 36 KB

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