One of the neatest new features in phpLiveDocx 1.2, which was officially launched yesterday, is the ability to save a document to a number of image files (one image file per page of the document).
In addition to the supported document file formats, phpLiveDocx 1.2 can now save documents as BMP, GIF, JPG, PNG and TIFF.
In the latest distribution file, in the directory /samples/mail-merge/bitmaps, you will find the following sample. The new methods to look out for are getAllBitmaps($zoomFactor, $format) and getBitmaps($fromPage, $toPage, $zoomFactor, $format).
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 | $mailMerge = new Zend_Service_LiveDocx_MailMerge(); $mailMerge->setUsername('myUsername') ->setPassword('myPassword'); $mailMerge->setLocalTemplate('template.docx'); $mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9') ->assign('licensee', 'Henry Döner-Meyer') ->assign('company', 'Co-Operation') ->assign('date', 'January 11, 2010') ->assign('time', 'January 11, 2010') ->assign('city', 'Berlin') ->assign('country', 'Germany'); $mailMerge->createDocument(); // Get all bitmaps $bitmaps = $mailMerge->getAllBitmaps(100, 'png'); // zoomFactor, format // Get just bitmaps in specified range //$bitmaps = $mailMerge->getBitmaps(2, 2, 100, 'png'); // fromPage, toPage, zoomFactor, format foreach ($bitmaps as $pageNumber => $bitmapData) { $filename = sprintf('documentPage%d.png', $pageNumber); file_put_contents($filename, $bitmapData); } unset($mailMerge); |
This produces the following two files (documentPage1.png and documentPage2.png) and writes them to disk in the same directory as the executable PHP code (click to enlarge):
To try this out for yourself, you will need to update to phplivedocx-1.2-20090810 or newer.

