OpenOffice2HTML ver 0.1.1 class DOCS
AUTHOR: Piotr MaliĆski
Contact: riklaunim@gmail.com
Site: http://www.english.rk.edu.pl | http://www.cms.rk.edu.pl - Polish
License: GPL
Requirements: PHP5 + simpleXML (and PECL ZIP extension is recommended)
Update 22.10.2005 (0.1.1): Added AbiWord support, few fixes in CSS generation from OASIS OpenDocument (OOffice 2), integration of PECL ZIP extension.
This class can extract data from OpenOffice 1.* and 2.* files (OOffice Writer - *.sxv or *.odt files) and AbiWord .abw files.
Currently only simple text/image styles can be converted (bold, italic, unterline, align, font size, font name etc.). Also tables should be converted but without any styles.
OpenOffice files are ZIP files (special subtype), just change their extension to zip and unzip it :) You will get some *.xml files and folders. The class can't extract zip files but you can use like PclZip (http://www.phpconcept.net) to extract data from a ZIP/OOffice file via PHP. If you want something better try PECL extension.
AbiWord is a small but usefull WYSIWYG editor that runs on Windows or Linux/Unix. *.abw files are plain XML files. This class can convert AbiWord files into HTML (with limited styles conversion).
HOW TO USE
You need an AbiWord file or OpenOffice one. If you want to convert OOffice files the you will need a "ZIP" PECL extension or you will have to manualy (or via other PHP way) extract OpenOffice file.
Examples with comments are in test.zip file.
METHODS:
oo_unzip($file, $save = false) - $file is a patch to OpenOffice file. IF $save is not false then content.xml and Pictures/ will be saved in the current folder (you have to have write permissions). IF $save is false the it will return an array array($content, $img); where $content is the content of content.xml and $img is an array with images (if any) where Keys are filenames, values - image files content.
oo_convert($content, $ver) - $content - patch to content.xml or it content (like from oo_unzip without save), $ver - OpenOffice version - 1 for old sxv files, 2 for OASIS odt files. IT will return an array: array($r_styles, $r_text); where $r_styles - CSS styles, $r_text - converted text, will return false on errors.
oo_to_file($filename, $content, $ver) - Saves the converted document to a HTML files. $filename - name of the output HTML file, $content, $ver - like in oo_convert(). Returns true on succes.
oo_on_screen($content, $ver) - returns a string with converted document. $content, $ver - like in oo_convert()
abi_on_screen($filename, $patch = './') - Converts AbiWord file and show the results (returns a string). $filename - patch to abiword file, $patch - where to save images (a patch)
ToDo
- More styles for OOffice Writer
- Check other OOffice files like Calc...