12
Aug
Written by: Jonathan Maron. Stored in: Samples.

Another useful feature of phpLiveDocx 1.2, is the ability to append one document to another. All you have to do is assign multiple sets of data to phpLiveDocx, in the form of a multi-depth associative array (see below). Each sub array (see set 1, set 2 etc.) is used to to create one document. Each newly created document is appended to the previous one.

Sound complicated? It is not!

First of all, download append-template.docx. Then run the following code. The result is one file append-document.pdf, which contains 4 pages. Once page per set of data.

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
$mailMerge = new Zend_Service_LiveDocx_MailMerge();
 
$mailMerge->setUsername('myUsername')
          ->setPassword('myPassword');
 
$mailMerge->setLocalTemplate('./append-template.docx');
 
$fieldValues = array (
    // set 1
    array (
        'software' => 'Magic Graphical Compression Suite v2.5',
        'name'     => 'Henry Richards'
    ),
    // set 2
    array (
        'software' => 'Magic CAD Suite v1.9',
        'name'     => 'Brüno Cassidy'
    ),
    // set 3
    array (
        'software' => 'Super Ray Tracer 19.2',
        'name'     => 'Paul Roberts'
    ),
    // set 4
    array (
        'software' => 'Random File Downloader 0.1a',
        'name'     => 'Kay Sandler'
    )                    
);
 
$mailMerge->assign($fieldValues);
 
$mailMerge->createDocument();
 
$data = $mailMerge->retrieveDocument('pdf');
 
file_put_contents('./append-document.pdf', $data);

This is a very simple sample, with a very simple template. However, this functionality is especially useful for scenarios, such as label printing and voucher or certificate creation.

If you need any help, please do not hesitate to post into the support forum.

One Response to “Appending documents in phpLiveDocx 1.2”

  1. Stephen Says:

    Is it possible to append two word or two pdfs together? possibly using a text field at the end of one template?

Leave a Reply