help developing an editor to view openoffice files.

Ken Starks straton at lampsacos.demon.co.uk
Tue Mar 13 11:29:08 EDT 2007


krishnakant Mane wrote:
> hello,
> right now I am involved on doing a very important accessibility work.
> as many people may or may not know that I am a visually handicap
> person and work a lot on accessibility.  the main issue at hand is to
> create an accessible editor for open office.
> there are a lot of things remaining on that front.
> so right now I am trying to find out a temporary work around by
> creating a simple accessible editor (with wxpython) for viewing and
> editing open office files.
> I know there must be python libraries that can open/ save .odt files
> because it is an open standard any ways.
> but I am trying to work out a kind of a program where those files can
> also be displayed in a text area with all the formatting.
> probably one way of doing it is to use some thing like a rich text
> editor and allow the file to be converted to rtf from odt for viewing
> and back again to odt when the user wishes to save it.
> another way I find is to actually find out if there is a odt text box
> that can display these files as they are.
> viewing the contents of the files in an editable way is most important.
> any suggestions?
> regards.
> Krishnakant.

There is an O'Reilly Book about hacking the Open Office Format, and
it is available free on line in both html and pdf.

Open office files are a variation on 'Zipped' archives and
many unzip tools can be used to open them, apart from ones
that insist on a .zip extension. These include python tools.

The one 'case study' in the book that uses python is actually for
a spreadsheet, but that makes little difference to the
'unzipping' part.  You can find it at:

http://books.evc-cit.info/odbook/ch05.html#modify-spreadsheet-section

Once you have the raw XML you should be able to convert it to any one of
many more accessible XML formats, for screen readers, brail
printers and so on. I don't know much about them, but hopefully you
do!

Don't re-invent the wheel! You will find quite a few ways on the Open
Office Wiki for converting the format to other things. You can also
daisy-tail the XSLT files; for example use one to convert to xhtml and
a second that converts xhtml to text.

Example (Display write files in the 'Firefox' browser).
http://wiki.services.openoffice.org/wiki/Firefox_ODFReader_extension


Don't forget that Open Office already has PDF export facilities, and
Acrobat reader already has some accessibility ability for simple 
documents (i.e single column, 'start at the beginning, keep going until
you get to the end, and then stop'). For adding structure to other PDF 
files you would need Acrobat Professional or software that can export 
'tagged' PDFs.

The case-study code is:

import xml.dom
import xml.dom.ext
import xml.dom.minidom
import xml.parsers.expat
import sys
import od_number
from zipfile import *
from StringIO import *

if (len(sys.argv) == 4):

     #   Open an existing OpenDocument file
     #
     inFile = ZipFile( sys.argv[1] )

     #   ...and a brand new output file
     #
     outFile = ZipFile( sys.argv[2], "w", ZIP_DEFLATED );

     getParameters( sys.argv[3] )

     #
     #   modify all appropriate currency styles
     #
     fixCurrency( "styles.xml" )
     fixCurrency( "content.xml" )

     #
     #   copy the manifest
     #
     copyManifest( )

     inFile.close
     outFile.close
else:
     print "Usage: " + sys.argv[0] + " inputfile outputfile parameterfile"



More information about the Python-list mailing list