Published 2011-01-18 00:00:00

 It's yet another "solve this quickly and cheaply" problems....

How to produce nice Word documents with images and all, without ending up doing lots of hard coded PHP calling some obtuse library in a way that would be difficult to maintain.

This one took a bit longer than expected, my first idea was to generate HTML files, then run them through abiword's command line, as that was the hints I got from googling.

abiword --to=doc  myfile.html

Unfortunately, although looking at abiwords source code, it should have  worked, nothing actually came out. After trying a few other magic tools like unoconv I was getting close to admitting defeat.

However, after a nice walk away from the desk and putting the thinking cap on, it came to me.. abw is abiwords xml file format. It's about as simple as HTML. So why not generate a abw file, and convert that into word.

Images in abw files are just base64 at the end of the file, each given a specific name, and reference in the body of the document where you want to use them. Trivial to generate... and even easier if you cheat a little by not using an dom based xml generator for the content (good old Flexy templates). then just run them through abiword as planned.

abiword --to=doc  myfile.abw

Quick, easy and pretty Word documents generated from web pages..

Comments

Great Idea!
Thanks a lot!

I've been looking for a way to convert HTML into DOC for some time now. And this seems to be a suitable solution. Could you provide a little bit more information about how you convert HTML to ABW? You mentioned that you don't use a DOM based xml generator but ... Flexy Templates? I' afraid I don't know them.

Best regards,
Robert
#0 - Robert Vogel ( Link) on 2011-01-19 15:40:58 Delete Comment
The sample template
We do not actually use HTML, but we treat the abiword file like a HTML file - the example template is here.

http://www.roojs.com/examples/word_report.txt

Just use this as a template using http://pear.php.net/HTML_Template_Flexy

and as long as you do not have strange data, it should output a valid abiword file, which can be converted to word using the lines above.
#1 - Alan Knowles ( Link) on 2011-01-24 15:21:28 Delete Comment

Add Your Comment