Zend_Service_LiveDocx.xml 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 19452 -->
  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 ist ein <acronym>SOAP</acronym> Service der es Entwicklern erlaubt Word
  10. Dokumente zu erstellen indem strukturierte Daten von PHP mit einem Template kombiniert
  11. werden, die in einer Word Bearbeitung erstellt wurden. Das resultierende Dokument kann
  12. als <acronym>PDF</acronym>, <acronym>DOCX</acronym>, <acronym>DOC</acronym>,
  13. <acronym>HTML</acronym> oder <acronym>RTF</acronym> Datei gespeichert werden. LiveDocx
  14. implementiert <ulink url="http://en.wikipedia.org/wiki/Mail_merge">mail-merge</ulink>
  15. in PHP.
  16. </para>
  17. <para>
  18. Die Familie der <classname>Zend_Service_LiveDocx</classname> Komponenten bietet ein
  19. klares und einfaches Interface zur <ulink url="http://www.livedocx.com">LiveDocx
  20. API</ulink> und bietet zusätzlich Funktionalitäten um die Geschwindigkeit im
  21. Netzwerk zu erhöhen.
  22. </para>
  23. <para>
  24. Wenn man, zusätzlich zu diesem Kapitel des Handbuchs, daran interessiert ist mehr
  25. über <classname>Zend_Service_LiveDocx</classname> und das dahinterliegende
  26. <acronym>SOAP</acronym> Service LiveDocx zu lernen, kann man bei den folgenden
  27. Ressourcen nachsehen:
  28. </para>
  29. <itemizedlist>
  30. <listitem>
  31. <para>
  32. <emphasis>Mitgelieferte Beispielanwendungen</emphasis>. Es gibt eine große
  33. Anzahl an Beispielanwendungen im Verzeichnis
  34. <emphasis>/demos/Zend/Service/LiveDocx</emphasis> der Zend Framework
  35. Distributiondatei, oder der Trunk Version die vom standardmäßigen SVN
  36. repository ausgecheckt werden kann. Diese sind dazu gedacht schnell, in nur
  37. ein paar Minuten, mit <classname>Zend_Service_LiveDocx</classname> zurecht zu
  38. kommen.
  39. </para>
  40. </listitem>
  41. <listitem>
  42. <para>
  43. <ulink url="http://www.phplivedocx.org/">
  44. <classname>Zend_Service_LiveDocx</classname> Blog und Webseite</ulink>.
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. <ulink url="http://www.livedocx.com/pub/documentation/api.aspx">
  50. LiveDocx SOAP API Dokumentation</ulink>.
  51. </para>
  52. </listitem>
  53. <listitem>
  54. <para>
  55. <ulink url="https://api.livedocx.com/1.2/mailmerge.asmx?wsdl">
  56. LiveDocx WSDL</ulink>.
  57. </para>
  58. </listitem>
  59. <listitem>
  60. <para>
  61. <ulink url="https://www.livedocx.com/">LiveDocx Blog und Webseite</ulink>.
  62. </para>
  63. </listitem>
  64. </itemizedlist>
  65. <sect3 id="zend.service.livedocx.account">
  66. <title>Für einen Account anmelden</title>
  67. <para>
  68. Bevor man damit beginnt LiveDocx zu verwenden muss man sich zuerst für einen Account
  69. <ulink
  70. url="https://www.livedocx.com/user/account_registration.aspx">anmelden</ulink>.
  71. Der Account ist komplett kostenlos, und mann muss nur einen
  72. <emphasis>Benutzernamen</emphasis>, ein <emphasis>Passwort</emphasis> und eine
  73. <emphasis>E-Mail Adresse</emphasis> spezifizieren. Die Anmeldedaten werden mit der
  74. Email Adresse verknüpft, welche man angibt, deshalb sollte man vorsichtig tippen.
  75. </para>
  76. </sect3>
  77. <sect3 id="zend.service.livedocx.templates-documents">
  78. <title>Templates und Dokumente</title>
  79. <para>
  80. LiveDocx unterscheidet zwischen den folgenden Ausdrücken: 1)
  81. <emphasis>Template</emphasis> und 2) <emphasis>Dokument</emphasis>. Um die
  82. Dokumentation und auch die aktuelle API vollständig zu verstehen, ist es wichtig
  83. das jeder Programmierer der LiveDocx ausliefert, den Unterschied versteht.
  84. </para>
  85. <para>
  86. Der Ausdruck <emphasis>Template</emphasis> wird verwendet um auf eine Eingabedatei
  87. zu verweisen, die in einem Word Prozessor erstellt wurde, und Formatierungen sowie
  88. Textfelder enthält. Man kann ein <ulink
  89. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-template.docx">Beispieltemplate</ulink>
  90. downloaden, welches als <acronym>DOCX</acronym> Datei gespeichert ist. Der Ausdruck
  91. <emphasis>Dokument</emphasis> wird verwendet um auf eine Ausgabedatei zu verweisen
  92. welche die Templatedatei enthält, zusammen mit Daten - z.B. das fertiggestellte
  93. Dokument. Man kann ein <ulink
  94. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-document.pdf">Beispieldokument</ulink>
  95. downloaden, welches als <acronym>PDF</acronym> Datei gespeichert ist.
  96. </para>
  97. </sect3>
  98. <sect3 id="zend.service.livedocx.formats">
  99. <title>Unterstützte Dateiformate</title>
  100. <para>
  101. LiveDocx unterstützt die folgenden Dateiformate:
  102. </para>
  103. <sect4 id="zend.service.livedocx.formats.template">
  104. <title>Template Dateiformate (Eingabe)</title>
  105. <para>
  106. Templates können in jedem der folgenden Dateiformate gespeichert werden:
  107. </para>
  108. <itemizedlist>
  109. <listitem>
  110. <para>
  111. <ulink url="http://en.wikipedia.org/wiki/Office_Open_XML">DOCX</ulink> -
  112. Office Open <acronym>XML</acronym> Format
  113. </para>
  114. </listitem>
  115. <listitem>
  116. <para>
  117. <ulink url="http://en.wikipedia.org/wiki/DOC_(computing)">DOC</ulink> -
  118. Microsoft Word <acronym>DOC</acronym> Format
  119. </para>
  120. </listitem>
  121. <listitem>
  122. <para>
  123. <ulink url="http://en.wikipedia.org/wiki/Rich_Text_Format">RTF</ulink> -
  124. Rich Text Dateiformat
  125. </para>
  126. </listitem>
  127. <listitem>
  128. <para>
  129. <ulink url="http://www.textcontrol.com/">TXD</ulink> - TX Text Control
  130. Format
  131. </para>
  132. </listitem>
  133. </itemizedlist>
  134. </sect4>
  135. <sect4 id="zend.service.livedocx.formats.document">
  136. <title>Dokument Dateiformate (Ausgabe):</title>
  137. <para>
  138. Das resultierende Dokument kann in jedem der folgenden Dateiformate gespeichert
  139. werden:
  140. </para>
  141. <itemizedlist>
  142. <listitem>
  143. <para>
  144. <ulink url="http://en.wikipedia.org/wiki/Office_Open_XML">DOCX</ulink> -
  145. Office Open <acronym>XML</acronym> Format
  146. </para>
  147. </listitem>
  148. <listitem>
  149. <para>
  150. <ulink url="http://en.wikipedia.org/wiki/DOC_(computing)">DOC</ulink> -
  151. Microsoft Word <acronym>DOC</acronym> Format
  152. </para>
  153. </listitem>
  154. <listitem>
  155. <para>
  156. <ulink url="http://en.wikipedia.org/wiki/Xhtml">HTML</ulink> -
  157. <acronym>XHTML</acronym> 1.0 Transitional Format
  158. </para>
  159. </listitem>
  160. <listitem>
  161. <para>
  162. <ulink url="http://en.wikipedia.org/wiki/Rich_Text_Format">RTF</ulink> -
  163. Rich Text File Format
  164. </para>
  165. </listitem>
  166. <listitem>
  167. <para>
  168. <ulink
  169. url="http://en.wikipedia.org/wiki/Portable_Document_Format">PDF</ulink>
  170. - Acrobat Portable Document Format
  171. </para>
  172. </listitem>
  173. <listitem>
  174. <para>
  175. <ulink url="http://www.textcontrol.com/">TXD</ulink> - TX Text Control
  176. Format
  177. </para>
  178. </listitem>
  179. <listitem>
  180. <para>
  181. <ulink url="http://en.wikipedia.org/wiki/Text_file">TXT</ulink> -
  182. <acronym>ANSI</acronym> reiner Text
  183. </para>
  184. </listitem>
  185. </itemizedlist>
  186. </sect4>
  187. <sect4 id="zend.service.livedocx.formats.image">
  188. <title>Bild Dateiformate (Ausgabe):</title>
  189. <para>
  190. Das resultierende Dokument kann in jedem der folgenden grafischen Dateiformate
  191. gespeichert werden:
  192. </para>
  193. <itemizedlist>
  194. <listitem>
  195. <para>
  196. <ulink url="http://en.wikipedia.org/wiki/BMP_file_format">BMP</ulink> -
  197. Bitmap Image Format
  198. </para>
  199. </listitem>
  200. <listitem>
  201. <para>
  202. <ulink url="http://en.wikipedia.org/wiki/GIF">GIF</ulink> - Graphics
  203. Interchange Format
  204. </para>
  205. </listitem>
  206. <listitem>
  207. <para>
  208. <ulink url="http://en.wikipedia.org/wiki/Jpg">JPG</ulink> - Joint
  209. Photographic Experts Group Format
  210. </para>
  211. </listitem>
  212. <listitem>
  213. <para>
  214. <ulink
  215. url="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</ulink>
  216. - Portable Network Graphics Format
  217. </para>
  218. </listitem>
  219. <listitem>
  220. <para>
  221. <ulink
  222. url="http://en.wikipedia.org/wiki/Tagged_Image_File_Format">TIFF</ulink>
  223. - Tagged Image File Format
  224. </para>
  225. </listitem>
  226. <listitem>
  227. <para>
  228. <ulink url="http://en.wikipedia.org/wiki/Windows_Metafile">WMF</ulink> -
  229. Windows Meta File Format
  230. </para>
  231. </listitem>
  232. </itemizedlist>
  233. </sect4>
  234. </sect3>
  235. </sect2>
  236. <sect2 id="zend.service.livedocx.mailmerge">
  237. <title>Zend_Service_LiveDocx_MailMerge</title>
  238. <para>
  239. <classname>Zend_Service_LiveDocx_MailMerge</classname> ist das mail-merge Objekt in der
  240. <classname>Zend_Service_LiveDocx</classname> Familie.
  241. </para>
  242. <sect3 id="zend.service.livedocx.mailmerge.generation">
  243. <title>Prozess der Dokumentenerstellung</title>
  244. <para>
  245. Der Prozess der Erstellung des Dokuments kann mit der folgenden Gleichung
  246. vereinfacht dargestellt werden:
  247. </para>
  248. <para>
  249. <emphasis>Template + Daten = Dokument</emphasis>
  250. </para>
  251. <para>
  252. Oder durch das folgende Diagramm ausgedrückt werden:
  253. </para>
  254. <mediaobject>
  255. <imageobject>
  256. <imagedata
  257. fileref="figures/zend.service.livedocx.mailmerge.generation-diabasic.png"
  258. format="PNG"></imagedata>
  259. </imageobject>
  260. <caption>
  261. <para>
  262. Daten werden in ein Template eingefügt um ein Dokument zu erstellen (<ulink
  263. url="figures/zend.service.livedocx.mailmerge.generation-diabasic_zoom.png">größer
  264. darstellen</ulink>).
  265. </para>
  266. </caption>
  267. </mediaobject>
  268. <para>
  269. Ein Template das in einer Word Bearbeitungsanwendung, wie Microsoft Word, erstellt
  270. wird, wurd in LiveDocx geladen. Daten werden kann in das Template eingesetzt, und
  271. das resultierende Dokument wird in jedes der unterstützten Formate gespeichert.
  272. </para>
  273. </sect3>
  274. <sect3 id="zend.service.livedocx.mailmerge.templates">
  275. <title>Erstellen von Templates in Microsoft Word 2007</title>
  276. <para>
  277. Man muss damit beginnen Microsoft Word zu starten und ein neues Dokument zu
  278. erstellen. Als nächstes, wird der Dialog <emphasis>Felder</emphasis> geöffnet.
  279. Er sieht wie folgt aus:
  280. </para>
  281. <mediaobject>
  282. <imageobject>
  283. <imagedata
  284. fileref="figures/zend.service.livedocx.mailmerge.templates-msworddialog.png"
  285. format="PNG"></imagedata>
  286. </imageobject>
  287. <caption>
  288. <para>
  289. Dialogbox Felder in Microsoft Word 2007 (<ulink
  290. url="figures/zend.service.livedocx.mailmerge.templates-msworddialog_zoom.png">größer
  291. darstellen</ulink>).
  292. </para>
  293. </caption>
  294. </mediaobject>
  295. <para>
  296. Durch Verwendung dieses Dialogs kann man die benötigten Merge-Felder in das eigene
  297. Dokument einfügen. Anbei ist ein Screenshot der Lizenz Vereinbarung in Microsoft
  298. Word 2007. Die Merge Felder sind als <code>{ MERGEFIELD FieldName }</code> markiert:
  299. </para>
  300. <mediaobject>
  301. <imageobject>
  302. <imagedata
  303. fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatefull.png"
  304. format="PNG"></imagedata>
  305. </imageobject>
  306. <caption>
  307. <para>
  308. Das Template in Microsoft Word 2007 (<ulink
  309. url="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatefull_zoom.png">größer
  310. darstellen</ulink>).
  311. </para>
  312. </caption>
  313. </mediaobject>
  314. <para>
  315. Jetzt muss das Template als <emphasis>template.docx</emphasis> gespeichert werden.
  316. </para>
  317. <para>
  318. Im nächsten Schritt veröffentlichen wir die Merge-Felder mit textuellen Daten von
  319. PHP.
  320. </para>
  321. <mediaobject>
  322. <imageobject>
  323. <imagedata
  324. fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatecropped.png"
  325. format="PNG"></imagedata>
  326. </imageobject>
  327. <caption>
  328. <para>
  329. Unterteiltes Template in Microsoft Word 2007 (<ulink
  330. url="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatecropped_zoom.png">größer
  331. darstellen</ulink>).
  332. </para>
  333. </caption>
  334. </mediaobject>
  335. <para>
  336. Um die Merge Felder, im vorher unterteilten Screenshot des <ulink
  337. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-template.docx">Templates</ulink>,
  338. in Microsoft Word auszufüllen, muss das folgende geschrieben werden:
  339. </para>
  340. <programlisting language="php"><![CDATA[
  341. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  342. $phpLiveDocx->setUsername('myUsername')
  343. ->setPassword('myPassword');
  344. $phpLiveDocx->setLocalTemplate('template.docx');
  345. $phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
  346. ->assign('licensee', 'Henry Döner-Meyer')
  347. ->assign('company', 'Co-Operation');
  348. $phpLiveDocx->createDocument();
  349. $document = $phpLiveDocx->retrieveDocument('pdf');
  350. file_put_contents('document.pdf', $document);
  351. ]]></programlisting>
  352. <para>
  353. Das resultierende Dokument wird auf die Festplatte in die Datei
  354. <emphasis>document.pdf</emphasis> geschrieben. Diese Datei kann nun weiter
  355. bearbeitet, per Email versendet oder einfach angezeigt werden, wie anbei im
  356. <emphasis>Document Viewer 2.26.1</emphasis> auf <emphasis>Ubuntu 9.04</emphasis>
  357. gezeigt:
  358. </para>
  359. <mediaobject>
  360. <imageobject>
  361. <imagedata
  362. fileref="figures/zend.service.livedocx.mailmerge.templates-msworddocument.png"
  363. format="PNG"></imagedata>
  364. </imageobject>
  365. <caption>
  366. <para>
  367. Resultierendes Dokument als <acronym>PDF</acronym> im Document Viewer 2.26.1
  368. (<ulink
  369. url="figures/zend.service.livedocx.mailmerge.templates-msworddocument_zoom.png">größer
  370. darstellen</ulink>).
  371. </para>
  372. </caption>
  373. </mediaobject>
  374. </sect3>
  375. <sect3 id="zend.service.livedocx.mailmerge.advanced">
  376. <title>Gehobeneres Mail-Merge</title>
  377. <para>
  378. <classname>Zend_Service_LiveDocx_MailMerge</classname> erlaubt es Entwicklern eine
  379. beliebige Anzahl an Text Feldern in ein Template einzufügen. Diese textfelder werden
  380. mit Daten gefüllt wenn <emphasis>createDocument()</emphasis> aufgerufen wird.
  381. </para>
  382. <para>
  383. Zusätzlich zu Textfeldern ist es auch mäglich spezielle Regionen eines Dokuments
  384. zu spezifizieren, welche wiederholt werden sollen.
  385. </para>
  386. <para>
  387. In einer Telefonrechnung ist es z.b. notwendig eine Liste aller Verbindungen,
  388. inklusive der Zielnummern, der Dauer und den Kosten jedes Anrufs auszudrucken.
  389. Diese Funktion der wiederholten Zeile kann mit sogenannten Blöcken erzielt werden.
  390. </para>
  391. <para>
  392. <emphasis>Blöcke</emphasis> sind einfach Regionen eines Dokuments, welche wiederholt
  393. werden wenn <methodname>createDocument()</methodname> aufgerufen wird. In einem
  394. Block kann eine beliebige Anzahl an <emphasis>Block Feldern</emphasis> spezifiziert
  395. werden.
  396. </para>
  397. <para>
  398. Blöcke bestehen aus zwei zusammenhängenden Dokument-Zielen mit einem eindeutigen
  399. Namen. Der folgende Screenshot zeigt diese Ziele und deren Namen in Rot:
  400. </para>
  401. <mediaobject>
  402. <imageobject>
  403. <imagedata
  404. fileref="figures/zend.service.livedocx.mailmerge.advanced-mergefieldblockformat.png"
  405. format="PNG"></imagedata>
  406. </imageobject>
  407. <caption>
  408. <para>
  409. (<ulink
  410. url="figures/zend.service.livedocx.mailmerge.advanced-mergefieldblockformat_zoom.png">größer
  411. darstellen</ulink>).
  412. </para>
  413. </caption>
  414. </mediaobject>
  415. <para>
  416. Das Format eines Blocks ist wie folgt:
  417. </para>
  418. <programlisting language="text"><![CDATA[
  419. blockStart_ + unique name
  420. blockEnd_ + unique name
  421. ]]></programlisting>
  422. <para>Zum Beispiel:</para>
  423. <programlisting language="text"><![CDATA[
  424. blockStart_block1
  425. blockEnd_block1
  426. ]]></programlisting>
  427. <para>
  428. Der Inhalt eines Blocks wird wiederholt, bis alle zugeordneten Daten in Blockfeldern
  429. des Templates eingefügt wurden. Die Daten der Blockfelder werden in PHP als
  430. mehrfach-assoziatives Array spezifiziert.
  431. </para>
  432. <para>
  433. Der folgende Screenshot eines Templates in Microsoft Word 2007 zeigt wie Blockfelder
  434. verwendet werden:
  435. </para>
  436. <mediaobject>
  437. <imageobject>
  438. <imagedata
  439. fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblockstemplate.png"
  440. format="PNG"></imagedata>
  441. </imageobject>
  442. <caption>
  443. <para>
  444. Template, welches Blöcke in Microsoft Word 2007 zeigt (<ulink
  445. url="figures/zend.service.livedocx.mailmerge.advanced-mswordblockstemplate_zoom.png">größer
  446. darstellen</ulink>).
  447. </para>
  448. </caption>
  449. </mediaobject>
  450. <para>
  451. Der folgende Code füllt das obige Template mit Daten.
  452. </para>
  453. <programlisting language="php"><![CDATA[
  454. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  455. $phpLiveDocx->setUsername('myUsername')
  456. ->setPassword('myPassword');
  457. $phpLiveDocx->setLocalTemplate('template.doc');
  458. $billConnections = array(
  459. array(
  460. 'connection_number' => '+49 421 335 912',
  461. 'connection_duration' => '00:00:07',
  462. 'fee' => '€ 0.03',
  463. ),
  464. array(
  465. 'connection_number' => '+49 421 335 913',
  466. 'connection_duration' => '00:00:07',
  467. 'fee' => '€ 0.03',
  468. ),
  469. array(
  470. 'connection_number' => '+49 421 335 914',
  471. 'connection_duration' => '00:00:07',
  472. 'fee' => '€ 0.03',
  473. ),
  474. array(
  475. 'connection_number' => '+49 421 335 916',
  476. 'connection_duration' => '00:00:07',
  477. 'fee' => '€ 0.03',
  478. ),
  479. );
  480. $phpLiveDocx->assign('connection', $billConnections);
  481. // ... andere Daten hier anhängen ...
  482. $phpLiveDocx->createDocument();
  483. $document = $phpLiveDocx->retrieveDocument('pdf');
  484. file_put_contents('document.pdf', $document);
  485. ]]></programlisting>
  486. <para>
  487. Die Daten, welche im Array <varname>$billConnections</varname> spezifiziert sind,
  488. werden im Template im Block 'connection' wiederholt. Die Schlüssel des Arrays
  489. (<varname>connection_number</varname>, <varname>connection_duration</varname> und
  490. <varname>fee</varname>) sind die Namen der Blockfelder - deren Daten werden bei
  491. jeder Iteration in einer Zeile eingefügt.
  492. </para>
  493. <para>
  494. Das resultierende Dokument wird auf die Festplatte in die Datei
  495. <emphasis>document.pdf</emphasis> geschrieben. Diese Datei kann anschließend
  496. nachbearbietet, per Email gesendet, oder einfach dargestellt werden, wie anbei im
  497. <emphasis>Document Viewer 2.26.1</emphasis> unter <emphasis>Ubuntu 9.04</emphasis>
  498. gezeigt:
  499. </para>
  500. <mediaobject>
  501. <imageobject>
  502. <imagedata
  503. fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblocksdocument.png"
  504. format="PNG"></imagedata>
  505. </imageobject>
  506. <caption>
  507. <para>
  508. Das resultierende Dokument als <acronym>PDF</acronym> im Document Viewer
  509. 2.26.1 (<ulink
  510. url="figures/zend.service.livedocx.mailmerge.advanced-mswordblocksdocument_zoom.png">größer
  511. darstellen</ulink>).
  512. </para>
  513. </caption>
  514. </mediaobject>
  515. <para>
  516. Man kann die <acronym>DOC</acronym> <ulink
  517. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-template.doc">Template
  518. Datei</ulink> und das resultierende <ulink
  519. url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-document.pdf">PDF
  520. Dokument</ulink> hier herunterladen.
  521. </para>
  522. <para>
  523. <emphasis>BEACHTE:</emphasis> Blöcke können nicht verschachtelt werden.
  524. </para>
  525. </sect3>
  526. <sect3 id="zend.service.livedocx.mailmerge.bitmaps">
  527. <title>Erstellen von Bitmap Bildern</title>
  528. <para>
  529. Zusätzlich zu den Dateiformaten für Dokumente erlaubt es
  530. <classname>Zend_Service_LiveDocx_MailMerge</classname> auch Dokumente als eine
  531. Anzahl von Bildern zu speichern (<acronym>BMP</acronym>,
  532. <acronym>GIF</acronym>, <acronym>JPG</acronym>, <acronym>PNG</acronym> und
  533. <acronym>TIFF</acronym>). Jede Seite des Dokuments wird als eine Datei gespeichert.
  534. </para>
  535. <para>
  536. Das folgende Beispiel zeigt die Verwendung von <methodname>getBitmaps($fromPage,
  537. $toPage, $zoomFactor, $format)</methodname> und
  538. <methodname>getAllBitmaps($zoomFactor, $format)</methodname>.
  539. </para>
  540. <para>
  541. <varname>$fromPage</varname> ist die untere Grenze der Seitenzahl des Bereichs an
  542. Seiten die als Bild zurückgegeben werden soll, und <varname>$toPage</varname> ist
  543. die obere Grenze der Seitenzahlen. <varname>$zoomFactor</varname> ist die Größe
  544. der Bilder, als Prozentwert, relativ zur originalen Seitengröße. Der Bereich dieses
  545. Parameters ist von 10 bis 400. <varname>$format</varname> ist das Format des
  546. Bildes welches von dieser Methode zurückgegeben wird. Die unterstützten Formate
  547. erhält man, wenn man <methodname>getImageFormats()</methodname> aufruft.
  548. </para>
  549. <programlisting language="php"><![CDATA[
  550. $date = new Zend_Date();
  551. $date->setLocale('en_US');
  552. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  553. $phpLiveDocx->setUsername('myUsername')
  554. ->setPassword('myPassword');
  555. $phpLiveDocx->setLocalTemplate('template.docx');
  556. $phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
  557. ->assign('licensee', 'Daï Lemaitre')
  558. ->assign('company', 'Megasoft Co-operation')
  559. ->assign('date', $date->get(Zend_Date::DATE_LONG))
  560. ->assign('time', $date->get(Zend_Date::TIME_LONG))
  561. ->assign('city', 'Lyon')
  562. ->assign('country', 'France');
  563. $phpLiveDocx->createDocument();
  564. // Alle Bitmaps holen
  565. // (zoomFactor, format)
  566. $bitmaps = $phpLiveDocx->getAllBitmaps(100, 'png');
  567. // Nur Bitmaps im spezifizierten Bereich erhalten
  568. // (fromPage, toPage, zoomFactor, format)
  569. // $bitmaps = $phpLiveDocx->getBitmaps(2, 2, 100, 'png');
  570. foreach ($bitmaps as $pageNumber => $bitmapData) {
  571. $filename = sprintf('documentPage%d.png', $pageNumber);
  572. file_put_contents($filename, $bitmapData);
  573. }
  574. ]]></programlisting>
  575. <para>
  576. Das produziert zwei Bilder (<filename>documentPage1.png</filename> und
  577. <filename>documentPage2.png</filename>) und schreibt diese auf der Festplatte
  578. in das gleiche Verzeichnis wie die ausführbare PHP Datei.
  579. </para>
  580. <mediaobject>
  581. <imageobject>
  582. <imagedata
  583. fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage1.png"
  584. format="PNG"></imagedata>
  585. </imageobject>
  586. <caption>
  587. <para>
  588. documentPage1.png (<ulink
  589. url="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage1_zoom.png">größer
  590. darstellen</ulink>).
  591. </para>
  592. </caption>
  593. </mediaobject>
  594. <mediaobject>
  595. <imageobject>
  596. <imagedata
  597. fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage2.png"
  598. format="PNG"></imagedata>
  599. </imageobject>
  600. <caption>
  601. <para>
  602. documentPage2.png (<ulink
  603. url="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage2_zoom.png">größer
  604. darstellen</ulink>).
  605. </para>
  606. </caption>
  607. </mediaobject>
  608. </sect3>
  609. <sect3 id="zend.service.livedocx.mailmerge.templates-types">
  610. <title>Local vs. Remote Templates</title>
  611. <para>
  612. Templates can be stored <emphasis>locally</emphasis>, on the client machine, or
  613. <emphasis>remotely</emphasis>, on the server. There are advantages and disadvantages
  614. to each approach.
  615. </para>
  616. <para>
  617. In the case that a template is stored locally, it must be transfered from the client
  618. to the server on every request. If the content of the template rarely changes, this
  619. approach is inefficient. Similarly, if the template is several megabytes in size, it
  620. may take considerable time to transfer it to the server. Local template are useful
  621. in situations in which the content of the template is constantly changing.
  622. </para>
  623. <para>
  624. The following code illustrates how to use a local template.
  625. </para>
  626. <programlisting language="php"><![CDATA[
  627. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  628. $phpLiveDocx->setUsername('myUsername')
  629. ->setPassword('myPassword');
  630. $phpLiveDocx->setLocalTemplate('./template.docx');
  631. // assign data and create document
  632. ]]></programlisting>
  633. <para>
  634. In the case that a template is stored remotely, it is uploaded once to the server
  635. and then simply referenced on all subsequent requests. Obviously, this is much
  636. quicker than using a local template, as the template does not have to be transfered
  637. on every request. For speed critical applications, it is recommended to use the
  638. remote template method.
  639. </para>
  640. <para>
  641. The following code illustrates how to upload a template to the server:
  642. </para>
  643. <programlisting language="php"><![CDATA[
  644. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  645. $phpLiveDocx->setUsername('myUsername')
  646. ->setPassword('myPassword');
  647. $phpLiveDocx->uploadTemplate('template.docx');
  648. ]]></programlisting>
  649. <para>
  650. The following code illustrates how to reference the remotely stored template on all
  651. subsequent requests:
  652. </para>
  653. <programlisting language="php"><![CDATA[
  654. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  655. $phpLiveDocx->setUsername('myUsername')
  656. ->setPassword('myPassword');
  657. $phpLiveDocx->setRemoteTemplate('template.docx');
  658. // assign data and create document
  659. ]]></programlisting>
  660. </sect3>
  661. <sect3 id="zend.service.livedocx.mailmerge.information">
  662. <title>Getting Information</title>
  663. <para>
  664. <classname>Zend_Service_LiveDocx_MailMerge</classname> provides a number of methods
  665. to get information on field names, available fonts and supported formats.
  666. </para>
  667. <example id="zend.service.livedocx.mailmerge.information.getfieldname">
  668. <title>Get Array of Field Names in Template</title>
  669. <para>
  670. The following code returns and displays an array of all field names in the
  671. specified template. This functionality is useful, in the case that you create an
  672. application, in which an end-user can update a template.
  673. </para>
  674. <programlisting language="php"><![CDATA[
  675. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  676. $phpLiveDocx->setUsername('myUsername')
  677. ->setPassword('myPassword');
  678. $templateName = 'template-1-text-field.docx';
  679. $phpLiveDocx->setLocalTemplate($templateName);
  680. $fieldNames = $phpLiveDocx->getFieldNames();
  681. foreach ($fieldNames as $fieldName) {
  682. printf('- %s%s', $fieldName, PHP_EOL);
  683. }
  684. ]]></programlisting>
  685. </example>
  686. <example id="zend.service.livedocx.mailmerge.information.getblockfieldname">
  687. <title>Get Array of Block Field Names in Template</title>
  688. <para>
  689. The following code returns and displays an array of all block field names in the
  690. specified template. This functionality is useful, in the case that you create an
  691. application, in which an end-user can update a template. Before such templates
  692. can be populated, it is necessary to find out the names of the contained block
  693. fields.
  694. </para>
  695. <programlisting language="php"><![CDATA[
  696. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  697. $phpLiveDocx->setUsername('myUsername')
  698. ->setPassword('myPassword');
  699. $templateName = 'template-block-fields.doc';
  700. $phpLiveDocx->setLocalTemplate($templateName);
  701. $blockNames = $phpLiveDocx->getBlockNames();
  702. foreach ($blockNames as $blockName) {
  703. $blockFieldNames = $phpLiveDocx->getBlockFieldNames($blockName);
  704. foreach ($blockFieldNames as $blockFieldName) {
  705. printf('- %s::%s%s', $blockName, $blockFieldName, PHP_EOL);
  706. }
  707. }
  708. ]]></programlisting>
  709. </example>
  710. <example id="zend.service.livedocx.mailmerge.information.getfontnames">
  711. <title>Get Array of Fonts Installed on Server</title>
  712. <para>
  713. The following code returns and displays an array of all fonts installed on the
  714. server. You can use this method to present a list of fonts which may be used in
  715. a template. It is important to inform the end-user about the fonts installed on
  716. the server, as only these fonts may be used in a template. In the case that a
  717. template contains fonts, which are not available on the server,
  718. font-substitution will take place. This may lead to undesirable results.
  719. </para>
  720. <programlisting language="php"><![CDATA[
  721. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  722. $phpLiveDocx->setUsername('myUsername')
  723. ->setPassword('myPassword');
  724. Zend_Debug::dump($phpLiveDocx->getFontNames());
  725. ]]></programlisting>
  726. <para>
  727. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  728. infrequently, it is highly recommended to use a cache, such as
  729. <classname>Zend_Cache</classname> - this will considerably speed up your
  730. application.
  731. </para>
  732. </example>
  733. <example id="zend.service.livedocx.mailmerge.information.gettemplateformats">
  734. <title>Get Array of Supported Template File Formats</title>
  735. <para>
  736. The following code returns and displays an array of all supported template file
  737. formats. This method is particularly useful in the case that a combo list should
  738. be displayed that allows the end-user to select the input format of the
  739. documentation generation process.
  740. </para>
  741. <programlisting language="php"><![CDATA[
  742. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge()
  743. $phpLiveDocx->setUsername('myUsername')
  744. ->setPassword('myPassword');
  745. Zend_Debug::dump($phpLiveDocx->getTemplateFormats());
  746. ]]></programlisting>
  747. <para>
  748. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  749. infrequently, it is highly recommended to use a cache, such as
  750. <classname>Zend_Cache</classname> - this will considerably speed up your
  751. application.
  752. </para>
  753. </example>
  754. <example id="zend.service.livedocx.mailmerge.information.getdocumentformats">
  755. <title>Get Array of Supported Document File Formats</title>
  756. <para>
  757. The following code returns and displays an array of all supported document file
  758. formats. This method is particularly useful in the case that a combo list should
  759. be displayed that allows the end-user to select the output format of the
  760. documentation generation process.
  761. </para>
  762. <programlisting language="php"><![CDATA[
  763. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  764. $phpLiveDocx->setUsername('myUsername')
  765. ->setPassword('myPassword');
  766. Zend_Debug::dump($phpLiveDocx->getDocumentFormats());
  767. ]]></programlisting>
  768. </example>
  769. <example id="zend.service.livedocx.mailmerge.information.getimageformats">
  770. <title>Get Array of Supported Image File Formats</title>
  771. <para>
  772. The following code returns and displays an array of all supported image file
  773. formats. This method is particularly useful in the case that a combo list should
  774. be displayed that allows the end-user to select the output format of the
  775. documentation generation process.
  776. </para>
  777. <programlisting language="php"><![CDATA[
  778. $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
  779. $phpLiveDocx->setUsername('myUsername')
  780. ->setPassword('myPassword');
  781. Zend_Debug::dump($phpLiveDocx->getImageFormats());
  782. ]]></programlisting>
  783. <para>
  784. <emphasis>NOTE:</emphasis> As the return value of this method changes very
  785. infrequently, it is highly recommended to use a cache, such as
  786. <classname>Zend_Cache</classname> - this will considerably speed up your
  787. application.
  788. </para>
  789. </example>
  790. </sect3>
  791. </sect2>
  792. </sect1>
  793. <!--
  794. vim:se ts=4 sw=4 tw=100 et:
  795. -->