1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.service.livedocx">
<title>Zend_Service_LiveDocx</title>
<sect2 id="zend.service.livedocx.introduction">
<title>Introduction to LiveDocx</title>
<para>
LiveDocx is a <acronym>SOAP</acronym> service that allows developers to generate word
processing documents by combining structured data from <acronym>PHP</acronym> with a
template, created in a word processor. The resulting document can be saved as a
<acronym>PDF</acronym>, <acronym>DOCX</acronym>, <acronym>DOC</acronym>,
<acronym>HTML</acronym> or <acronym>RTF</acronym> file. LiveDocx implements <ulink
url="http://en.wikipedia.org/wiki/Mail_merge">mail-merge</ulink> in
<acronym>PHP</acronym>.
</para>
<para>
The family of <classname>Zend_Service_LiveDocx</classname> components provides a clean
and simple interface to the <ulink url="http://www.livedocx.com">LiveDocx API</ulink>
and additionally offers functionality to improve network performance.
</para>
<para>
In addition to this section of the manual, if you are interested in learning more about
<classname>Zend_Service_LiveDocx</classname> and the backend <acronym>SOAP</acronym>
service LiveDocx, please take a look at the following resources:
</para>
<itemizedlist>
<listitem>
<para>
<emphasis>Shipped demonstration applications</emphasis>. There are a large
number of demonstration applications in the directory
<emphasis>/demos/Zend/Service/LiveDocx</emphasis> of the Zend Framework
distribution file or trunk version, checked out of the standard SVN repository.
These are designed to get you up to speed with
<classname>Zend_Service_LiveDocx</classname> within a matter of minutes.
</para>
</listitem>
<listitem>
<para>
<ulink url="http://www.phplivedocx.org/">
<classname>Zend_Service_LiveDocx</classname> blog and web site</ulink>.
</para>
</listitem>
<listitem>
<para>
<ulink url="http://www.livedocx.com/pub/documentation/api.aspx">
LiveDocx SOAP API documentation</ulink>.
</para>
</listitem>
<listitem>
<para>
<ulink url="https://api.livedocx.com/1.2/mailmerge.asmx?wsdl">
LiveDocx WSDL</ulink>.
</para>
</listitem>
<listitem>
<para>
<ulink url="https://www.livedocx.com/">LiveDocx blog and web site</ulink>.
</para>
</listitem>
</itemizedlist>
<sect3 id="zend.service.livedocx.account">
<title>Sign Up for an Account</title>
<para>
Before you can start using LiveDocx, you must first <ulink
url="https://www.livedocx.com/user/account_registration.aspx">sign up</ulink>
for an account. The account is completely free of charge and you only need to
specify a <emphasis>username</emphasis>, <emphasis>password</emphasis> and
<emphasis>e-mail address</emphasis>. Your login credentials will be dispatched to
the e-mail address you supply, so please type carefully.
</para>
</sect3>
<sect3 id="zend.service.livedocx.templates-documents">
<title>Templates and Documents</title>
<para>
LiveDocx differentiates between the following terms: 1)
<emphasis>template</emphasis> and 2) <emphasis>document</emphasis>. In order to
fully understand the documentation and indeed the actual <acronym>API</acronym>, it
is important that any programmer deploying LiveDocx understands the difference.
</para>
<para>
The term <emphasis>template</emphasis> is used to refer to the input file, created
in a word processor, containing formatting and text fields. You can download an
<ulink
url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-template.docx">example
template</ulink>, stored as a <acronym>DOCX</acronym> file. The term
<emphasis>document</emphasis> is used to refer to the output file that contains the
template file, populated with data - i.e. the finished document. You can download an
<ulink
url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-document.pdf">example
document</ulink>, stored as a <acronym>PDF</acronym> file.
</para>
</sect3>
<sect3 id="zend.service.livedocx.formats">
<title>Supported File Formats</title>
<para>
LiveDocx supports the following file formats:
</para>
<sect4 id="zend.service.livedocx.formats.template">
<title>Template File Formats (input)</title>
<para>
Templates can be saved in any of the following file formats:
</para>
<itemizedlist>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Office_Open_XML">DOCX</ulink> -
Office Open <acronym>XML</acronym> format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/DOC_(computing)">DOC</ulink> -
Microsoft Word <acronym>DOC</acronym> format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Rich_Text_Format">RTF</ulink> -
Rich text file format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://www.textcontrol.com/">TXD</ulink> - TX Text Control
format
</para>
</listitem>
</itemizedlist>
</sect4>
<sect4 id="zend.service.livedocx.formats.document">
<title>Document File Formats (output):</title>
<para>
The resulting document can be saved in any of the following file formats:
</para>
<itemizedlist>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Office_Open_XML">DOCX</ulink> -
Office Open <acronym>XML</acronym> format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/DOC_(computing)">DOC</ulink> -
Microsoft Word <acronym>DOC</acronym> format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Xhtml">HTML</ulink> -
<acronym>XHTML</acronym> 1.0 transitional format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Rich_Text_Format">RTF</ulink> -
Rich text file format
</para>
</listitem>
<listitem>
<para>
<ulink
url="http://en.wikipedia.org/wiki/Portable_Document_Format">PDF</ulink>
- Acrobat Portable Document Format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://www.textcontrol.com/">TXD</ulink> - TX Text Control
format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Text_file">TXT</ulink> -
<acronym>ANSI</acronym> plain text
</para>
</listitem>
</itemizedlist>
</sect4>
<sect4 id="zend.service.livedocx.formats.imageimport">
<title>Image File Formats (import):</title>
<para>
Images can be merged into templates in any of following file formats:
</para>
<itemizedlist>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/BMP_file_format">BMP</ulink> -
Bitmap image format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/GIF">GIF</ulink> - Graphics
Interchange Format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Jpg">JPG</ulink> - Joint
Photographic Experts Group format
</para>
</listitem>
<listitem>
<para>
<ulink
url="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</ulink>
- Portable Network Graphics format
</para>
</listitem>
<listitem>
<para>
<ulink
url="http://en.wikipedia.org/wiki/Tagged_Image_File_Format">TIFF</ulink>
- Tagged Image File Format
</para>
</listitem>
</itemizedlist>
</sect4>
<sect4 id="zend.service.livedocx.formats.imageexport">
<title>Image File Formats (output):</title>
<para>
The resulting document can be exported to any of the following graphical file
formats:
</para>
<itemizedlist>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/BMP_file_format">BMP</ulink> -
Bitmap image format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/GIF">GIF</ulink> - Graphics
Interchange Format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Jpg">JPG</ulink> - Joint
Photographic Experts Group format
</para>
</listitem>
<listitem>
<para>
<ulink
url="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</ulink>
- Portable Network Graphics format
</para>
</listitem>
<listitem>
<para>
<ulink
url="http://en.wikipedia.org/wiki/Tagged_Image_File_Format">TIFF</ulink>
- Tagged Image File Format
</para>
</listitem>
<listitem>
<para>
<ulink url="http://en.wikipedia.org/wiki/Windows_Metafile">WMF</ulink> -
Windows Meta File format
</para>
</listitem>
</itemizedlist>
</sect4>
</sect3>
</sect2>
<sect2 id="zend.service.livedocx.mailmerge">
<title>Zend_Service_LiveDocx_MailMerge</title>
<para>
<classname>Zend_Service_LiveDocx_MailMerge</classname> is the mail-merge object in the
<classname>Zend_Service_LiveDocx</classname> family.
</para>
<sect3 id="zend.service.livedocx.mailmerge.generation">
<title>Document Generation Process</title>
<para>
The document generation process can be simplified with the following equation:
</para>
<para>
<emphasis>Template + Data = Document</emphasis>
</para>
<para>
Or expressed by the following diagram:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.generation-diabasic_zoom.png"
format="PNG" />
</para>
<para>
Data is inserted into template to create a document.
</para>
<para>
A template, created in a word processing application, such as Microsoft Word, is
loaded into LiveDocx. Data is then inserted into the template and the resulting
document is saved to any supported format.
</para>
</sect3>
<sect3 id="zend.service.livedocx.mailmerge.templates">
<title>Creating Templates in Microsoft Word 2007</title>
<para>
Start off by launching Microsoft Word and creating a new document. Next, open up the
<emphasis>Field</emphasis> dialog box. This looks as follows:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.templates-msworddialog_zoom.png"
format="PNG" />
</para>
<para>
Microsoft Word 2007 Field dialog box.
</para>
<para>
Using this dialog, you can insert the required merge fields into your document.
Below is a screenshot of a license agreement in Microsoft Word 2007. The merge
fields are marked as <command>{ MERGEFIELD FieldName }</command>:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatefull_zoom.png"
format="PNG" />
</para>
<para>
Template in Microsoft Word 2007.
</para>
<para>
Now, save the template as <emphasis>template.docx</emphasis>.
</para>
<para>
In the next step, we are going to populate the merge fields with textual data from
<acronym>PHP</acronym>.
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.templates-mswordtemplatecropped_zoom.png"
format="PNG" />
</para>
<para>
Cropped template in Microsoft Word 2007.
</para>
<para>
To populate the merge fields in the above cropped screenshot of the <ulink
url="http://www.phplivedocx.org/wp-content/uploads/2009/01/license-agreement-template.docx">template</ulink>
in Microsoft Word, all we have to code is as follows:
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$phpLiveDocx->setLocalTemplate('template.docx');
$phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
->assign('licensee', 'Henry Döner-Meyer')
->assign('company', 'Co-Operation');
$phpLiveDocx->createDocument();
$document = $phpLiveDocx->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
]]></programlisting>
<para>
The resulting document is written to disk in the file
<emphasis>document.pdf</emphasis>. This file can now be post-processed, sent via
e-mail or simply displayed, as is illustrated below in <emphasis>Document Viewer
2.26.1</emphasis> on <emphasis>Ubuntu 9.04</emphasis>:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.templates-msworddocument_zoom.png"
format="PNG" />
</para>
<para>
Resulting document as <acronym>PDF</acronym> in Document Viewer 2.26.1.
</para>
</sect3>
<sect3 id="zend.service.livedocx.mailmerge.imagemerge">
<title>Merging image data</title>
<para>
Using <classname>Zend_Service_LiveDocx_MailMerge</classname> it is also possible to merge images into
a template. This feature is useful, for example, in the case of a badge application
for a conference. In addition to the name and company name that should appear on
the badge, it is possible to insert a photo of the delegate, using the API.
</para>
<para>
Even it is sounds a little counter-intuitive, image-merging also work with
text fields, as described in the section above. In fact, inserting a text field
for an image is identical to inserting a text field for textual information.
The only difference is the naming convention of the text field. Whereas, a text
field for textual information can have (almost) any identifier, a text field for
an image must start with <emphasis>image:</emphasis>. For example, in the case of our badge
application, we would have the following 3 fields:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.templates-imagemerge_zoom.png"
format="PNG" />
</para>
<para>
The text field, into which image data will be inserted is called <emphasis>image:photo</emphasis>
and can be populated just like any other text field, using the assign method. The
text fields <emphasis>name</emphasis> and <emphasis>company</emphasis> are regular
text fields for textual information.
</para>
<para>
Before we insert graphic data, we first have to upload the image to the backend
LiveDocx server. This can be achieved using the <emphasis>uploadImage($filename)</emphasis> method.
</para>
<para>The following code snippet illustrates the flow:</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('username')
->setPassword('password');
$photoFilename = 'dailemaitre.jpg';
if (!$phpLiveDocx->imageExists($photoFilename)) {
$phpLiveDocx->uploadImage($photoFilename);
}
$phpLiveDocx->setLocalTemplate('template.docx');
$phpLiveDocx->assign('name', 'Daï Lemaitre')
->assign('company', 'Megasoft Co-operation')
->assign('date', Zend_Date::now()->toString(Zend_Date::DATE_LONG))
->assign('image:photo', $photoFilename);
$phpLiveDocx->createDocument();
$document = $phpLiveDocx->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
$phpLiveDocx->deleteImage($photoFilename);
]]></programlisting>
<para>
Note that all images uploaded to your LiveDocx account must have a unique
filename. In the case that you only intend to use the image once (such
as is probable for our badge application), it makes sense to immediately
delete it from the backend, using the <emphasis>deleteImage($filename)</emphasis> method.
</para>
</sect3>
<sect3 id="zend.service.livedocx.mailmerge.advanced">
<title>Advanced Mail-Merge</title>
<para>
<classname>Zend_Service_LiveDocx_MailMerge</classname> allows designers to insert
any number of text fields into a template. These text fields are populated with data
when <emphasis>createDocument()</emphasis> is called.
</para>
<para>
In addition to text fields, it is also possible specify regions of a document, which
should be repeated.
</para>
<para>
For example, in a telephone bill it is necessary to print out a list of all
connections, including the destination number, duration and cost of each call. This
repeating row functionality can be achieved with so called blocks.
</para>
<para>
<emphasis>Blocks</emphasis> are simply regions of a document, which are repeated
when <methodname>createDocument()</methodname> is called. In a block any number of
<emphasis>block fields</emphasis> can be specified.
</para>
<para>
Blocks consist of two consecutive document targets with a unique name. The following
screenshot illustrates these targets and their names in red:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.advanced-mergefieldblockformat_zoom.png"
format="PNG" />
</para>
<para>
The format of a block is as follows:
</para>
<programlisting language="text"><![CDATA[
blockStart_ + unique name
blockEnd_ + unique name
]]></programlisting>
<para>For example:</para>
<programlisting language="text"><![CDATA[
blockStart_block1
blockEnd_block1
]]></programlisting>
<para>
The content of a block is repeated, until all data assigned in the block fields has
been injected into the template. The data for block fields is specified in
<acronym>PHP</acronym> as a multi-assoc array.
</para>
<para>
The following screenshot of a template in Microsoft Word 2007 shows how block fields
are used:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblockstemplate_zoom.png"
format="PNG" />
</para>
<para>
Template, illustrating blocks in Microsoft Word 2007.
</para>
<para>
The following code populates the above template with data.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$phpLiveDocx->setLocalTemplate('template.doc');
$billConnections = array(
array(
'connection_number' => '+49 421 335 912',
'connection_duration' => '00:00:07',
'fee' => '€ 0.03',
),
array(
'connection_number' => '+49 421 335 913',
'connection_duration' => '00:00:07',
'fee' => '€ 0.03',
),
array(
'connection_number' => '+49 421 335 914',
'connection_duration' => '00:00:07',
'fee' => '€ 0.03',
),
array(
'connection_number' => '+49 421 335 916',
'connection_duration' => '00:00:07',
'fee' => '€ 0.03',
),
);
$phpLiveDocx->assign('connection', $billConnections);
// ... assign other data here ...
$phpLiveDocx->createDocument();
$document = $phpLiveDocx->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
]]></programlisting>
<para>
The data, which is specified in the array <varname>$billConnections</varname> is
repeated in the template in the block connection. The keys of the array
(<varname>connection_number</varname>, <varname>connection_duration</varname> and
<varname>fee</varname>) are the block field names - their data is inserted, one row
per iteration.
</para>
<para>
The resulting document is written to disk in the file
<emphasis>document.pdf</emphasis>. This file can now be post-processed, sent via
e-mail or simply displayed, as is illustrated below in <emphasis>Document Viewer
2.26.1</emphasis> on <emphasis>Ubuntu 9.04</emphasis>:
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.advanced-mswordblocksdocument_zoom.png"
format="PNG" />
</para>
<para>
Resulting document as <acronym>PDF</acronym> in Document Viewer 2.26.1.
</para>
<para>
You can download the <acronym>DOC</acronym> <ulink
url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-template.doc">template
file</ulink> and the resulting <ulink
url="http://www.phplivedocx.org/wp-content/uploads/2009/01/telephone-bill-document.pdf">PDF
document</ulink>.
</para>
<para>
<emphasis>NOTE:</emphasis> blocks may not be nested.
</para>
</sect3>
<sect3 id="zend.service.livedocx.mailmerge.bitmaps">
<title>Generating bitmaps image files</title>
<para>
In addition to document file formats,
<classname>Zend_Service_LiveDocx_MailMerge</classname> also allows documents to be
exported to a number of image file formats (<acronym>BMP</acronym>,
<acronym>GIF</acronym>, <acronym>JPG</acronym>, <acronym>PNG</acronym> and
<acronym>TIFF</acronym>). Each page of the document is saved to one file.
</para>
<para>
The following sample illustrates the use of <methodname>getBitmaps($fromPage,
$toPage, $zoomFactor, $format)</methodname> and
<methodname>getAllBitmaps($zoomFactor, $format)</methodname>.
</para>
<para>
<varname>$fromPage</varname> is the lower-bound page number of the page range that
should be returned as an image and <varname>$toPage</varname> the upper-bound page
number. <varname>$zoomFactor</varname> is the size of the images, as a percent,
relative to the original page size. The range of this parameter is 10 to 400.
<varname>$format</varname> is the format of the images returned by this method. The
supported formats can be obtained by calling
<methodname>getImageExportFormats()</methodname>.
</para>
<programlisting language="php"><![CDATA[
$date = new Zend_Date();
$date->setLocale('en_US');
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$phpLiveDocx->setLocalTemplate('template.docx');
$phpLiveDocx->assign('software', 'Magic Graphical Compression Suite v1.9')
->assign('licensee', 'Daï Lemaitre')
->assign('company', 'Megasoft Co-operation')
->assign('date', $date->get(Zend_Date::DATE_LONG))
->assign('time', $date->get(Zend_Date::TIME_LONG))
->assign('city', 'Lyon')
->assign('country', 'France');
$phpLiveDocx->createDocument();
// Get all bitmaps
// (zoomFactor, format)
$bitmaps = $phpLiveDocx->getAllBitmaps(100, 'png');
// Get just bitmaps in specified range
// (fromPage, toPage, zoomFactor, format)
// $bitmaps = $phpLiveDocx->getBitmaps(2, 2, 100, 'png');
foreach ($bitmaps as $pageNumber => $bitmapData) {
$filename = sprintf('documentPage%d.png', $pageNumber);
file_put_contents($filename, $bitmapData);
}
]]></programlisting>
<para>
This produces two files (<filename>documentPage1.png</filename> and
<filename>documentPage2.png</filename>) and writes them to disk in the same
directory as the executable <acronym>PHP</acronym> file.
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage1_zoom.png"
format="PNG" />
</para>
<para>
documentPage1.png.
</para>
<para>
<inlinegraphic
fileref="figures/zend.service.livedocx.mailmerge.bitmaps-documentpage2_zoom.png"
format="PNG" />
</para>
<para>
documentPage2.png.
</para>
</sect3>
<sect3 id="zend.service.livedocx.mailmerge.templates-types">
<title>Local vs. Remote Templates</title>
<para>
Templates can be stored <emphasis>locally</emphasis>, on the client machine, or
<emphasis>remotely</emphasis>, on the server. There are advantages and disadvantages
to each approach.
</para>
<para>
In the case that a template is stored locally, it must be transfered from the client
to the server on every request. If the content of the template rarely changes, this
approach is inefficient. Similarly, if the template is several megabytes in size, it
may take considerable time to transfer it to the server. Local template are useful
in situations in which the content of the template is constantly changing.
</para>
<para>
The following code illustrates how to use a local template.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$phpLiveDocx->setLocalTemplate('./template.docx');
// assign data and create document
]]></programlisting>
<para>
In the case that a template is stored remotely, it is uploaded once to the server
and then simply referenced on all subsequent requests. Obviously, this is much
quicker than using a local template, as the template does not have to be transfered
on every request. For speed critical applications, it is recommended to use the
remote template method.
</para>
<para>
The following code illustrates how to upload a template to the server:
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$phpLiveDocx->uploadTemplate('template.docx');
]]></programlisting>
<para>
The following code illustrates how to reference the remotely stored template on all
subsequent requests:
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$phpLiveDocx->setRemoteTemplate('template.docx');
// assign data and create document
]]></programlisting>
</sect3>
<sect3 id="zend.service.livedocx.mailmerge.information">
<title>Getting Information</title>
<para>
<classname>Zend_Service_LiveDocx_MailMerge</classname> provides a number of methods
to get information on field names, available fonts and supported formats.
</para>
<example id="zend.service.livedocx.mailmerge.information.getfieldname">
<title>Get Array of Field Names in Template</title>
<para>
The following code returns and displays an array of all field names in the
specified template. This functionality is useful, in the case that you create an
application, in which an end-user can update a template.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$templateName = 'template-1-text-field.docx';
$phpLiveDocx->setLocalTemplate($templateName);
$fieldNames = $phpLiveDocx->getFieldNames();
foreach ($fieldNames as $fieldName) {
printf('- %s%s', $fieldName, PHP_EOL);
}
]]></programlisting>
</example>
<example id="zend.service.livedocx.mailmerge.information.getblockfieldname">
<title>Get Array of Block Field Names in Template</title>
<para>
The following code returns and displays an array of all block field names in the
specified template. This functionality is useful, in the case that you create an
application, in which an end-user can update a template. Before such templates
can be populated, it is necessary to find out the names of the contained block
fields.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
$templateName = 'template-block-fields.doc';
$phpLiveDocx->setLocalTemplate($templateName);
$blockNames = $phpLiveDocx->getBlockNames();
foreach ($blockNames as $blockName) {
$blockFieldNames = $phpLiveDocx->getBlockFieldNames($blockName);
foreach ($blockFieldNames as $blockFieldName) {
printf('- %s::%s%s', $blockName, $blockFieldName, PHP_EOL);
}
}
]]></programlisting>
</example>
<example id="zend.service.livedocx.mailmerge.information.getfontnames">
<title>Get Array of Fonts Installed on Server</title>
<para>
The following code returns and displays an array of all fonts installed on the
server. You can use this method to present a list of fonts which may be used in
a template. It is important to inform the end-user about the fonts installed on
the server, as only these fonts may be used in a template. In the case that a
template contains fonts, which are not available on the server,
font-substitution will take place. This may lead to undesirable results.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
Zend_Debug::dump($phpLiveDocx->getFontNames());
]]></programlisting>
<para>
<emphasis>NOTE:</emphasis> As the return value of this method changes very
infrequently, it is highly recommended to use a cache, such as
<classname>Zend_Cache</classname> - this will considerably speed up your
application.
</para>
</example>
<example id="zend.service.livedocx.mailmerge.information.gettemplateformats">
<title>Get Array of Supported Template File Formats</title>
<para>
The following code returns and displays an array of all supported template file
formats. This method is particularly useful in the case that a combo list should
be displayed that allows the end-user to select the input format of the
documentation generation process.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge()
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
Zend_Debug::dump($phpLiveDocx->getTemplateFormats());
]]></programlisting>
<para>
<emphasis>NOTE:</emphasis> As the return value of this method changes very
infrequently, it is highly recommended to use a cache, such as
<classname>Zend_Cache</classname> - this will considerably speed up your
application.
</para>
</example>
<example id="zend.service.livedocx.mailmerge.information.getdocumentformats">
<title>Get Array of Supported Document File Formats</title>
<para>
The following code returns and displays an array of all supported document file
formats. This method is particularly useful in the case that a combo list should
be displayed that allows the end-user to select the output format of the
documentation generation process.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
Zend_Debug::dump($phpLiveDocx->getDocumentFormats());
]]></programlisting>
</example>
<example id="zend.service.livedocx.mailmerge.information.getimageimportformats">
<title>Get Array of Supported Image Import File Formats</title>
<para>
The following code returns and displays an array of all supported imput image file
formats.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
Zend_Debug::dump($phpLiveDocx->getImageImportFormats());
]]></programlisting>
<para>
<emphasis>NOTE:</emphasis> As the return value of this method changes very
infrequently, it is highly recommended to use a cache, such as
<classname>Zend_Cache</classname> - this will considerably speed up your
application.
</para>
</example>
<example id="zend.service.livedocx.mailmerge.information.getimageexportformats">
<title>Get Array of Supported Image Export File Formats</title>
<para>
The following code returns and displays an array of all supported export image file
formats. This method is particularly useful in the case that a combo list should
be displayed that allows the end-user to select the output format of the
documentation generation process.
</para>
<programlisting language="php"><![CDATA[
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('myUsername')
->setPassword('myPassword');
Zend_Debug::dump($phpLiveDocx->getImageExportFormats());
]]></programlisting>
<para>
<emphasis>NOTE:</emphasis> As the return value of this method changes very
infrequently, it is highly recommended to use a cache, such as
<classname>Zend_Cache</classname> - this will considerably speed up your
application.
</para>
</example>
</sect3>
</sect2>
</sect1>
<!--
vim:se ts=4 sw=4 tw=100 et:
-->
|