#!/usr/local/bin/python2.4 #coding: latin-1 #Ab Python2.3 ist die uncodierte Verwendung von Umlauten deprecated. import cgi import pyopenoffice import sys import os import cgitb import copy # cgitb.enable() testlist = [{"Surname": "Simon", "FirstName": "Martin", "Postcode": "08309", "City": "Eibenstock"}, {"Surname": "Miller", "FirstName": "Steve", "Postcode": "12345", "City": "Nowhere-City"}, {"Surname": "Smith", "FirstName": "John", "Postcode": "54321", "City": "Everywhere"}] form = cgi.FieldStorage() ie_problem = 0 if form.has_key("ie_problem"): ie_problem = 1 try: mode = (form["action"])[0].value #print form["action"] #sys.exit() content = form["clientfile"].value contentfile = open("inputfile","wb") contentfile.write(content) contentfile.close() newfile = "inputfile" tool = pyopenoffice.PyOpenOffice() if mode == "sxw2txt": outfiles = tool.makePlainText(newfile,plain_text_output=1) print "Content-type: text/plain\n" newtxt = open(outfiles[0],"rb") txt = newtxt.read() print txt newtxt.close() if mode in ("sxw2sxw_picrepl", "sxw2pdf_picrepl"): newfile = tool.replacePictures(newfile,["posaunen3.gif","posaunen2.gif","posaunen3.gif"]) if mode in ("sxw2sxw_serial", "sxw2pdf_serial"): newfile = tool.makeSerialLetters(newfile,testlist) if mode in ("sxw2pdf", "sxw2pdf_serial", "sxw2pdf_picrepl"): backup_file = copy.copy(newfile) try: newfile = tool.unpackNormalize(newfile) os.system("xsltproc normalized_oo2rml.xsl %s > test.xml" % newfile) outfiles = tool.makeSafePdf("test.xml",RML=1) if outfiles == []: # error in makeSafePdf raise IOError except: # try the "Old Way", it's safer outfiles = tool.makeSafePdf(backup_file) newpdf = open(outfiles[0],"rb") if ie_problem: print "Content-disposition: attachment; filename=output.pdf\n" else: print "Content-type: application/pdf\n" pdf = newpdf.read() print pdf newpdf.close() elif mode in ("sxw2sxw_serial", "sxw2sxw_picrepl"): newsxw = open(newfile) if ie_problem: print "Content-disposition: attachment; filename=output.sxw\n" else: print "Content-type: application/vnd.sun.xml.writer\n" sxw = newsxw.read() print sxw newsxw.close() except: print "Content-type: text/html\n" print "

There was an error - Maybe you provided a Non-SXW-Document.

"