Zend_Service_LiveDocx.xml 36 KB

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