Related
Easy way to make Word documents with images from PHP
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..
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
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
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.
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.
Add a comment (requires javascript!)
Follow us
-
- Migrating off Netsuite - The hidden cost of Clouds..
- Javascript Templating, AngularJS and Roo.XTemplate
- Roo.XComponent introduction
- Roo J Solutions Limited is recruiting
- Free your data... seed webkit browser mirror button
- Deleting the View and Controller..
- What was I doing last night... Seed querying xscreensaver
- Watch-out PHP 5.3.7+ is about.. and the is_a() / __autoload() mess.
Blog Latest
-
Twitter - @Roojs

Comments