import uno import getopt, sys, os from unohelper import Base, systemPathToFileUrl, absolutize from com.sun.star.beans import PropertyValue from com.sun.star.script import CannotConvertException from com.sun.star.lang import IllegalArgumentException from com.sun.star.task import ErrorCodeIOException from com.sun.star.io import IOException, XOutputStream from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK from xml.dom import minidom import sys keep_trace='' def addToText(cursor,text,level,value): if level==1: cursor.NumberingStyleName = "NONE" cursor.ParaStyleName="Heading 1" text.insertString( cursor, value , 0 ) text.insertControlCharacter( cursor, PARAGRAPH_BREAK , 0 ) #print >> sys.stderr,' * Main Title : ' + value else: i=0 prefix='' while i < level-1: prefix+=' ' i+=1 cursor.NumberingStyleName="List "+str(level-1) text.insertString( cursor, prefix+value , 0 ) text.insertControlCharacter( cursor, PARAGRAPH_BREAK , 0 ) cursor.NumberingStyleName = "NONE" #print >> sys.stderr,dir(sys.stderr) #print >> sys.stderr,prefix+' * NumberingStyleName '+str(level-1)+' '+value.encode('iso-8859-15') def printChildren(cursor,text,node,level,keep_trace): if node.nodeType==3: level-=1 if not(node.nodeValue!=None and len(node.nodeValue.replace(' ',''))!=1 and keep_trace!='' and keep_trace!=None): if keep_trace!='': addToText(cursor,text,level-1,keep_trace) keep_trace=node.nodeName if node.hasChildNodes(): for i in node.childNodes: printChildren(cursor,text,i,level+1,keep_trace) keep_trace='' else: if node.nodeValue != None and len(node.nodeValue.replace(' ',''))>1: addToText(cursor,text,level-1,keep_trace+' : '+node.nodeValue) keep_trace='' else: if node.nodeValue != None and len(node.nodeValue.replace(' ',''))>1: addToText(cursor,text,level-1,keep_trace+' : '+node.nodeValue) keep_trace='' else: if keep_trace!='#text': addToText(cursor,text,level-1,keep_trace) keep_trace='' if node.nodeType==1 and node.hasAttributes(): i=0 while i> sys.stderr,' * 1st level' + i.nodeName if i.hasChildNodes(): for j in i.childNodes: printChildren(cursor,text,j,2,'') tmp=myDocument.StyleFamilies.getByName("NumberingStyles") tmp1=tmp.getByName("Puce 1") prop1Fich = ( PropertyValue( "FilterName" , 0, "writer_pdf_Export", 0 ),PropertyValue( "Overwrite" , 0, True , 0 ) ) outputDoc=systemPathToFileUrl("/tmp/output.pdf") myDocument.storeToURL(outputDoc,prop1Fich) myDocument.close(True) ctx.ServiceManager output["Document"]["value"]= open('/tmp/output.pdf', 'r').read() print >> sys.stderr,len(output["Document"]["value"]) return 3 #To run test from command line uncomment the following line: #xml2pdf({},{"file":{"value":"/tmp/demo.xml"},"doc":{"value":"/tmp/demo.odt"}},{})