Zend_Service_LiveDocx.xml 38 KB

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