As of phpLiveDocx 1.2, it is possible to generate documents in XHTML 1.0 Transitional. Thus, you can now convert any supported template file format (DOCX, DOC and RTF) to XHTML.
Consider the following example (discussion under the code):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $mailMerge = new Zend_Service_LiveDocx_MailMerge(); $mailMerge->setUsername('myUsername') ->setPassword('myPassword'); $mailMerge->setLocalTemplate('license-agreement.doc'); $mailMerge->assign(null); // must be called as of phpLiveDocx 1.2 $mailMerge->createDocument(); $data = $mailMerge->retrieveDocument('html'); file_put_contents('./license-agreement.htm', $data); |
We specify the document we want to to convert and then simply retrieve the document in the required format – XHTML in this case.
Please download the source document and converted document and take a look at the source code of the created HTML file.
You will see that the logo at the top left of the page is not linked in, as you may expect, but has been embedded in the HTML file, using the data URI scheme method. The markup to look out for is as follows:
1 2 3 4 5 6 | <img src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlz
AAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3
aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1e
xdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4M
khoXe0rZigAAAABJRU5ErkJggg==" alt="" /> |
The main advantage of this embedded approach is that a request is not required to download the image file; hence, it is easier to share the document around, in particular, if the recipient is not connected to a network when viewing the file.
The Wikipedia article offers a detailed discussion on the advantages and disadvantages of the data URI scheme approach.
April 28th, 2011 at 09:53
Image is missing in html document. in word document am seeing the logo image but in html page its missing
October 7th, 2011 at 09:14
[...] http://www.phplivedocx.org/2009/08/13/convert-docx-doc-rtf-to-html-in-php/ [...]