def labelSla(self): """ FIXME: Grave bug , non lascia il testo semplice nella cella in cui è presente anche un tag ... """ self.labelObj = self.slaPageObjects() index = -1 gr = [] for pageObject in self.labelObj: itexts = pageObject.findall('ITEXT') group = pageObject.get('GROUPS') if group in gr: for itext in itexts: attributes = itext.items() dictionary = {} for kk in range(0, len(attributes)): dictionary[attributes[kk][0]] = attributes[kk][1] ch = dictionary['CH'] tags = Sla2pdfUtils.findTags(ch) if tags: tagsKeys = tags.keys()[0] or [] function = tags[tagsKeys]['function'] parameter = tags[tagsKeys]['parameter'] if function == "bcview": bc = self.objects[index][tagsKeys] if bc == "None": bc = "0000000000000" value = "bcview;%s;%s;%s" %(bc, str(tags[tagsKeys]['parameter'].split('X')[0]), str(tags[tagsKeys]['parameter'].split('X')[1])) or "" elif tagsKeys in self.timeTags: value = Sla2pdfUtils.getNowValue(tagsKeys) else: value = self.objects[index][tagsKeys] or "" if function in self.formatFunctions and "X" not in parameter: resolvedTag = self.callFunction(function, value, parameter) value = ch.replace(tags[tagsKeys]['completeTag'], resolvedTag) else: value = str(value) else: value = ch if value.count('€') >1: value = value.replace('€', '', 1) itext.set('CH', value) else: gr.append(group) index += 1
def alignmentFunc(self,paras, v, monocell=False, reiter=False, trail=None): if monocell==True: try: # print "TRAIL DI MONOCELLA PER CURIOSI", trail slaAlignment = trail[0][0].get('ALIGN') except: slaAlignment = paras[0][0].get('ALIGN') elif reiter ==True: # print "TRAIL DEL REITER VEDIAMO UN PO?", trail[v][0].get('ALIGN') slaAlignment = trail[v][0].get('ALIGN') # if not slaAlignment: # slaAlignment = paras[0][0].get('ALIGN') else: try: # slaAlignment = trail[v][0].get('ALIGN') except: slaAlignment = paras[v][0].get('ALIGN') if not slaAlignment: # print "NON RIESCO AD ALLINEARE" slaAlignment = None if not slaAlignment: slaAlignment = self.slaStyleDefault() pdfAlignment= Sla2pdfUtils.alignment(slaAlignment) return pdfAlignment
def translate(self, label=False): # begin translate self.pageProperties = Sla2pdfUtils.pageProFunc(self.slaDocumentTag()) self.canvas = Canvas(filename = self.slafile + '.pdf', pagesize=(self.pageProperties[0][8],self.pageProperties[0][7])) # Page's table reiter = False self.pdfPage = 0 tablepropertys = self.findTablesProperties() iteratable = self.getIteratableGroups(tablepropertys) for self.pdfPage in xrange(0, self.numPages): print("PAGINA", self.pdfPage, "DI", self.numPages) if label: group = tablepropertys[self.pdfPage].keys()[0] tabpro = tablepropertys[self.pdfPage][group] reiter = True # Closing pages (elements of the same page must be near) if "noGroup" in group and tabpro["pfile"] != "": self.drawImage(group=group, tabpro=tabpro) # IMMAGINE elif "noGroup" in group and tabpro["pfile"] == "": self.drawTable(group=group, monocell=True, tabpro=tabpro) # MONOCELLA else: self.drawTable(group=group, reiter=reiter, tabpro=tabpro) # TABELLA self.canvas.saveState() self.canvas.showPage() else: for tableproperty in tablepropertys: for group in tableproperty.keys(): if self.pbar: pbar(self.pbar,pulse=True,text="GEN STAMPA ATTENDERE 2 di 2") tabpro = tableproperty[group] try: group= group.strip().split('%%%')[0] except: group= group.strip() if group in iteratable: colu = int(tabpro['columns']) # tabpro['iterproper'] = tabpro['parasobj'][colu:(colu*2)] reiter = True n_cells = int(tabpro['n_cells']) # Closing pages (elements of the same page must be near) if "noGroup" in group and tabpro["pfile"] != "" : self.drawImage(group=group, tabpro=tabpro) # IMMAGINE elif "noGroup" in group and tabpro["pfile"] == "": self.drawTable(group =group, monocell=True, tabpro=tabpro)# MONOCELLA else: self.drawTable(group =group, reiter = reiter, tabpro = tabpro) # TABELLA self.canvas.saveState() self.canvas.showPage() self.canvas.save() # temporary pdf file is removed immediately filename = self.slafile + '.pdf' f = file(filename, 'rb') result = f.read() f.close() # os.remove(filename) return result
def fontNameFunc(self, itext, monocell=False,v=None,trail=None): bold = False try: ch = itext.get('CH') if "<b>" in ch: bold=True except: bold= False if self.version: if bold: fontName = Sla2pdfUtils.getPdfFontName(str(itext.get('FONT')+"-bold")) else: fontName = Sla2pdfUtils.getPdfFontName(str(itext.get('FONT'))) else: if bold: fontName = Sla2pdfUtils.getPdfFontName(str(itext.get('CFONT')+"-bold")) else: fontName = Sla2pdfUtils.getPdfFontName(str(itext.get('CFONT'))) return fontName
def callFunction(self, functionName, value=None, parameter=None): """ Call a function by its functionName """ value = value or '' parameter = parameter or '' if functionName == 'trunc': if value == '' or parameter == '': return '' else: return Sla2pdfUtils.truncValue(value, int(parameter)) elif functionName == 'approx': if value == '' or parameter == '': return '' else: return Sla2pdfUtils.approxValue(value, int(parameter)) elif functionName == 'approxit': if value == '' or parameter == '': return '' else: return Sla2pdfUtils.approxValueIt(value, int(parameter)) elif functionName == 'itformat' or functionName == 'itformatdataora': if value == '': return '' else: return Sla2pdfUtils.itformatValue(value) elif functionName == 'itformatdata': if value == '': return '' else: return Sla2pdfUtils.itformatValue(value,tronca=True) elif functionName == 'bcview': if value == '': return '' else: #bcvalueTag= Sla2pdfUtils.bcviewValue(value, parameter) #return bcvalueTag return value else: return ''
def getPagesNumber(self): """ Al momento la funzione itera sulla lista dei gruppi con più righe scarta i tag non utili e verifica poi la lunghezza del dao e il numero di righe presenti, c'è da migliorarla ma per il momento funziona """ pags = [1] if not self.classic: pags = [len(self.objects)] else: for group in self.getIteratableGroups(self.tableProperties): gruppo = self.indexGroupTableFromListDict(group) cellsprop = [x.findall('ITEXT') for x in gruppo["cells"] if x.findall('ITEXT')] righe = [round(float(x.get('gYpos')),3) for x in gruppo["cells"]] rowsNumber = len(sorted(list(set(righe)))) for i in cellsprop: a = [g.get("CH") for g in i if "(n)" in g.get("CH")] for s in a: arrayName = Sla2pdfUtils.findTags(s).values()[0]["arrayName"] valuesNumber = len(self.objects[self.cycle][arrayName]) pagesNumber = int(math.ceil(float(valuesNumber) / float(rowsNumber))) pags.append(pagesNumber) return max(pags)
def drawTable(self, group=None, monocell=None, reiter = None, tabpro=None): """ Drawing a table """ matrix = [] lst = [] matrix2 = [] vector = [] # Total of element's table n_cells = int(tabpro['n_cells']) columns = int(tabpro['columns']) rows = int(tabpro['rows']) celle = tabpro["cells"] widths = [float(x.get("WIDTH")) for x in celle] heights = [float(x.get("HEIGHT")) for x in celle] xpos = [float(x.get("XPOS")) for x in celle] ypos = [float(x.get("YPOS")) for x in celle] contColumns = 0 ch = '' col = 0 cycle = False vector = [] alignment= None itexts = [x.findall("ITEXT") for x in celle] paras = [x.findall("para") for x in celle] trail = [x.findall("trail") for x in celle] stile = TableStyle([]) stile.add('VALIGN',(0,0),(-1,-1),'TOP') if monocell==True: cells = 1 columns=1 rows = 1 #print "CEEEEEEEEEEEEEELS", cells for v in range(0,n_cells): if v == 0: contRows = 0 contColumns = 0 elif columns==1: contColumns = -1 contRows= int(v/columns) else: contRows= int(v/columns) contColumns = ((v)%columns) # print "VVVVVVVVVVVVV E CELLE", "celle", celle,"V:",v, "LEN DI CELLE",len(celle), "NCELLS", n_cells, group try: background = self.backgroundFunc(celle[v])# Finding background except Exception as e: Environment.pg2log.info("ERRORE NEL GRUPPO TABELLA"+ group + "ERRORE:" + str(e.args)) hexBorderColor = self.hexBorderColorFunc(celle[v].get('PCOLOR2')) stile.add('ROWBACKGROUNDS', (contColumns,contRows), (contColumns,contRows), (background, background)) cellpict = celle[v].get('PFILE') cellIMGHeight = celle[v].get('HEIGHT') cellIMGWidth = celle[v].get('WIDTH') bordoriga = False if (celle[v].get('BottomLine') == "1" and celle[v].get('TopLine') == "1" and\ celle[v].get('LeftLine') =="1" and celle[v].get('RightLine') == "1"): stile.add('BOX', (contColumns,contRows), (contColumns,contRows), float(celle[v].get('PWIDTH')), hexBorderColor) bordoriga = True else: if celle[v].get('BottomLine') == "1": stile.add('LINEBELOW', (contColumns,contRows), (contColumns,contRows), float(celle[v].get('PWIDTH')), hexBorderColor) bordoriga = True if celle[v].get('TopLine') == "1": stile.add('LINEABOVE', (contColumns,contRows), (contColumns,contRows), float(celle[v].get('PWIDTH')), hexBorderColor) bordoriga = True if celle[v].get('LeftLine') == "1": stile.add('LINEBEFORE', (contColumns,contRows), (contColumns,contRows), float(celle[v].get('PWIDTH')), hexBorderColor) bordoriga = True if celle[v].get('RightLine') == "1": stile.add('LINEAFTER', (contColumns,contRows), (contColumns,contRows), float(celle[v].get('PWIDTH')), hexBorderColor) bordoriga = True if not bordoriga and str(celle[v].get('PCOLOR2')) != "None": stile.add('BOX', (contColumns,contRows), (contColumns,contRows), float(celle[v].get('PWIDTH')), hexBorderColor) if not monocell: ch = self.chFunc(itexts[v])[0] itext = self.chFunc(itexts[v])[1] else: try: itext = itexts[0] ch = itexts[0].get('CH') except: itext = None ch = "" actualPageObject = tabpro # Borders pdfAlignment = self.alignmentFunc(paras,v, monocell, trail=trail, reiter=reiter) #alignment stile.add('ALIGN', (contColumns,contRows), (contColumns,contRows), pdfAlignment) if itext != None: fontSize = self.fontSizeFunc(itext,v=v, trail=trail)# Font size stile.add('FONTSIZE', (contColumns,contRows), (contColumns,contRows), fontSize) fontName = self.fontNameFunc(itext,trail=trail) # Font name stile.add('FONT', (contColumns,contRows), (contColumns,contRows), fontName) foreground = self.foregroundFunc(itext) #foreground stile.add('TEXTCOLOR', (contColumns,contRows), (contColumns,contRows), foreground) if "bcview" in ch: alignment="LEFT" vector.append(Sla2pdfUtils.createbarcode(ch)) else: vector.append(Sla2pdfUtils.makeParagraphs(ch, background, foreground, alignment, fontName, fontSize)) elif cellpict: (imgPath, imgFile) = os.path.split(cellpict) path = Environment.imagesDir + imgFile widthIMG = (float(cellIMGHeight)-2)*100/(float(cellIMGWidth)-2) img = Image(path,width=widthIMG,height=float(cellIMGHeight)-2) vector.append(img) else: vector.append('') if monocell==True: cycle= True elif ((v+1)%columns) == 0: contRows = 0 cycle= True if cycle == True: matrix.append(vector) vector = [] cycle = False table=Table(matrix,style=stile, colWidths=widths[:columns], rowHeights=heights[:rows]) lst.append(table) # Effective table size sumRows = Sla2pdfUtils.sumRowsFunc(heights,rows) sumColumns = Sla2pdfUtils.sumColumnsFunc(widths,columns) f = Frame(x1=(xpos[0] - self.pageProperties[self.pdfPage][9]), y1=(self.pageProperties[self.pdfPage][7] - ypos[0] - sumRows + self.pageProperties[self.pdfPage][10] - 12), width=sumColumns, height=(sumRows+12), showBoundary=0) sumRows = sumColumns = 0 f.addFromList(lst, self.canvas) reiter = False
def duplicateElementLabel(self): """ Funzione base per la gestione delle frontaline: La gestione frontaline ha problematiche differenti rispetto ai report ed alle stampe singole. Il template contiene una frontalina di base che deve essere replicata enne volte quante dovuto uguale a se stessa per poi gestirne i tag rendendoli "iteranti". La parte meno complessa è quella della traduzione in pdf in quanto lo sla finito non rappresenta complessità particolari """ numPages = self.slaPage() document = self.slaDocumentTag() self.pageProperties = Sla2pdfUtils.pageProFunc(document) group = self.tablesProperties[0].keys()[0] self.tablesPropertie = self.tablesProperties[0][group] widths = [float(x.get("WIDTH")) for x in self.tablesPropertie['cells']] heights = [float(x.get("HEIGHT")) for x in self.tablesPropertie['cells']] cells = int(self.tablesPropertie['n_cells']) columns = int(self.tablesPropertie['columns']) rows = int(self.tablesPropertie['rows']) sumRows = reduce(operator.add, heights[:rows]) sumColumns = reduce(operator.add, widths[:columns]) otherColumn = sumColumns + (int(setconf("Label", "sistemacolonnafrontaline") or 0)) otherRows = sumRows + (int(setconf("Label", "sistemarigafrontaline") or 0 )) pageYpos = float(numPages[0].get('PAGEYPOS')) pageXpos = float(numPages[0].get('PAGEXPOS')) pageHeight = float(numPages[0].get('PAGEHEIGHT')) borderTop = float(numPages[0].get('BORDERTOP')) borderBottom = float(numPages[0].get('BORDERBOTTOM')) borderLeft = float(numPages[0].get('BORDERLEFT')) borderRight = float(numPages[0].get('BORDERRIGHT')) pageWidth = float(numPages[0].get('PAGEWIDTH')) realHeightPage = pageHeight - (borderTop + borderBottom) realWidthPage = pageWidth - (borderLeft + borderRight) NumMaxRowLabelForPage = int(realHeightPage/otherRows) NumMaxColumnLabelForPage = int(realWidthPage /otherColumn) NumMaxLabelForPageTotal = NumMaxRowLabelForPage*NumMaxColumnLabelForPage NumLabelInDao = len(self.objects) pagesNumber = int((NumLabelInDao/NumMaxLabelForPageTotal)) +1 self.createPageTag(pagesNumber) labelObj = self.slaPageObjects() for j in range(1, NumLabelInDao): for pageObject in labelObj: ## Creating dictionary attributes pageobject attributes = pageObject.items() dictionary = {} for k in range(0, len(attributes)): dictionary[attributes[k][0]] = attributes[k][1] ## Applying attributes app = pageObject.makeelement('PAGEOBJECT', dictionary) ## Creating dictionary attributes itext of the pageobject itexts = pageObject.findall('ITEXT') for itext in itexts: attributes = itext.items() dictionary = {} for kk in range(0, len(attributes)): dictionary[attributes[kk][0]] = attributes[kk][1] ## Applying attributes ElementTree.SubElement(app, 'ITEXT', dictionary) trails = pageObject.findall('trail') for trai in trails: attributes = trai.items() dictTrai = {} for attrrr in attributes: dictTrai[attrrr[0]] = attrrr[1] ElementTree.SubElement(app, 'trail', dictTrai) paras = pageObject.findall('para') for para in paras: attributes = para.items() dictPara = {} for kkk in range(0, len(attributes)): dictPara[attributes[kkk][0]] = attributes[kkk][1] ## Applying attributes ElementTree.SubElement(app, 'para', dictPara) pageItemAttributes = pageObject.findall('pageItemAttributes') ElementTree.SubElement(app, 'pageItemAttributes') ## Number page inigroup = str(pageObject.get('GROUPS')).strip() x = str(j+int(inigroup))+ " " app.set('GROUPS', x) app.set('OwnPage', str(j)) ## Coordinates ypos = pageObject.get('YPOS') height = pageObject.get('HEIGHT') xpos = pageObject.get('XPOS') if (j/NumMaxLabelForPageTotal) >= 1: page = int(j/NumMaxLabelForPageTotal) else: page = 0 colonna = NumMaxColumnLabelForPage- ((NumMaxLabelForPageTotal*(page+1) - (j+1)) / NumMaxRowLabelForPage)-1 riga = j- (NumMaxRowLabelForPage * (j/NumMaxRowLabelForPage)) if not j%NumMaxRowLabelForPage: app.set('YPOS',str(float(ypos)+((float(pageHeight)+float(borderTop))*page))) else: app.set('YPOS',str(float(ypos)+((float(pageHeight)+float(borderTop))*page)+ (otherRows* riga))) app.set('XPOS',str(float(xpos) + otherColumn* (colonna))) self.slaDocumentTag().append(app) app = {} # self.doc.write(self.pdfFolder+"_tempppPrima.sla") self.labelSla()
def fillDocument(self): """ Replacing tags with real values """ self.gruppi = self.findTablesProperties() iteranti = self.getIteratableGroups(self.gruppi) self.pageObjects = self.slaPageObjects() iterator = 0 while iterator < self.lenPageObjects(): if self.pbar: pbar(self.pbar,pulse=True,text="GENERAZIONE STAMPA ATTENDERE %s") %(str(iterator)) pageObject = self.pageObjects[iterator] isTableItem = pageObject.get('isTableItem') isGroupControl = pageObject.get('isGroupControl') pageNumber = int(pageObject.get('OwnPage')) + 1 group = str(pageObject.get('GROUPS')).strip() itexts = pageObject.findall('ITEXT') try: group= group.strip().split('%%%')[0] except: group = group pfile = pageObject.get('PFILE') if (pfile != ''): iterator += 1 continue if group: actualGroup = group if str(actualGroup).strip() not in iteranti: # Replacing non-iterator tags for itext in itexts: ch = itext.get('CH') tags = Sla2pdfUtils.findTags(ch) #print "Stampo il tag", tags if tags is not None: tagsKeys = tags.keys() #print "Dizionario dei tags tagsKeys", tagsKeys for tagkey in tagsKeys: if tagkey.replace(' ', '') == '': continue #try: resolvedTag = '' function = tags[tagkey]['function'] parameter = tags[tagkey]['parameter'] if "X" in parameter: parameter = parameter.split("X") if tagkey == 'currentPage': value = pageNumber elif tagkey == 'totalPage': value = self.pagesNumber elif tagkey in self.timeTags: value = Sla2pdfUtils.getNowValue(tagkey) else: if self.cycle <= (len(self.objects) - 1): try: value = self.objects[self.cycle][tagkey] or '' except: if "destinazione_merce" in tagkey: if tagkey == "destinazione_merce": value = self.daos.DM.denominazione or "" elif tagkey == "indirizzo_destinazione_merce": value = self.daos.DM.indirizzo elif tagkey == "localita_destinazione_merce": value = self.daos.DM.localita or "" elif tagkey == "cap_destinazione_merce": value = self.daos.DM.cap or "" elif tagkey == "provincia_destinazione_merce": value = self.daos.DM.provincia or "" #else: #try: else: value = '' # Function if function in self.formatFunctions: resolvedTag = uu(self.callFunction(function, value, parameter)) else: resolvedTag = uu(value) ch = ch.replace(tags[tagkey]['completeTag'], resolvedTag) # Save itext try: if value.count('€') >1: value = value.replace('€', '', 1) except: pass itext.set('CH', ch) else: if isGroupControl == '1': iterator += 1 continue for itext in itexts: ch = str(itext.get('CH')) if '<<' in ch and '>>' in ch: while (ch.find('<<') > -1) and (ch.find('>>') > -1): arrayIndex = int(ch[ch.find('<<')+2:ch.find('>>')]) ch = ch.replace(('<<%d>>' % arrayIndex), '') else: arrayIndex = -1 tags = Sla2pdfUtils.findTags(ch) if tags is not None: for k in tags.keys(): if k.replace(' ', '') == '': continue #try: resolvedTag = '' function = tags[k]['function'] parameter = tags[k]['parameter'] if k == 'currentPage': value = pageNumber elif k == 'totalPage': value = self.pagesNumber elif k in self.timeTags: value = Sla2pdfUtils.getNowValue(k) else: indexN = k.find('(n)') if '(n)' in k: indexNP = k.find('(n).') if '(n).' in k: arrayName = k[:indexNP] tagName = k[indexNP+4:] if self.cycle <= (len(self.objects) - 1): if arrayIndex <= (len(self.objects[self.cycle][arrayName]) - 1): arraySource = self.objects[self.cycle][arrayName][arrayIndex] if SHOWZERORIGA == True: value = arraySource[tagName] else: value = arraySource[tagName] or "" else: value = '' else: value = '' else: tagName = k[:indexN] if arrayIndex <= (len(self.objects) - 1): arraySource = self.objects[arrayIndex] if SHOWZEROTOTALI: value = str(arraySource[tagName]) else: value = arraySource[tagName] or '' else: value = '' else: if self.cycle <= (len(self.objects) - 1): value = self.objects[self.cycle][k] or '' else: value = '' # Function # print "FUCTION", function, value, parameter if function in self.formatFunctions: resolvedTag = uu(self.callFunction(function, value, parameter)) else: resolvedTag = uu(value) ch = ch.replace(tags[k]['completeTag'], resolvedTag) try: if value.count('€') >1: value = value.replace('€', '', 1) except: pass itext.set('CH', ch) iterator += 1
def duplicateTags(self): """ Dopo aver duplicato gli elementi adesso duplichiamo i tags TODO: refactoring di questa func""" self.gruppi = self.findTablesProperties() iteranti = self.getIteratableGroups(self.gruppi) for group in self.gruppi: rigaConItextDict = {} gruppo = group.values()[0] if "%%%" in gruppo["GROUPS"]: groupname= str(gruppo["GROUPS"].strip().split('%%%')[0]) else: groupname = str(gruppo["GROUPS"].strip()) if groupname in iteranti : # Qui vengono gestite le tabelle iterabili , e le righe cellsprop = [{x:[x,x.findall('ITEXT'),x.findall('para'), x.findall('trail')]} for x in gruppo["cells"]] colonne = [float(x.get('gXpos')) for x in gruppo["cells"]] righe = [float(x.get('gYpos')) for x in gruppo["cells"]] col = list(set(colonne)) col = sorted(col) rows = list(set(righe)) rows = sorted(rows) numeroRighe = len(rows)-1 for cel in cellsprop: # print "CELLLLLLLLLLLLLLLLA", cel CH = None tags = {} rowgg = rows.index(float(cel.values()[0][0].get("gYpos"))) pageNamber = int(cel.values()[0][0].get("OwnPage")) row = (numeroRighe*pageNamber)+rowgg for ite in cel.values()[0][1]: CH = ite.get("CH") tags = Sla2pdfUtils.findTags(CH) column = col.index(float(cel.values()[0][0].get("gXpos")))+1 # quelli con tag e CH sono quelli della seconda riga che poi dovrò andare a ciclare # nella prima riga c'è di norma solo un CH ma senza TAG if tags and CH: # build a dict with all second row data with tags and CH rigaConItextDict[str(column)+"%"+groupname] = [CH,tags,ite,cel] for k in tags.keys(): if k.replace(' ', '') is not '': if '(n)' in k : if tags[k]['position'] == 'last': row = rowgg tmp = self.getTagToPrint(CH, column = column,row=row-1, tags=tags,k=k, pageNamber=pageNamber) ite.set("CH", tmp) else: colu = int(col.index(float(cel.values()[0][0].get("gXpos")))+1) if str(colu)+"%"+groupname in rigaConItextDict: ch = rigaConItextDict[str(colu) +"%" + groupname][0] tags = rigaConItextDict[str(colu) +"%"+ groupname][1] ite = rigaConItextDict[str(colu)+"%"+groupname][2] ricel = rigaConItextDict[str(colu)+"%"+groupname][3] attributes = ite.items() itedict= {} for attrr in attributes: itedict[attrr[0]] = attrr[1] tmp = ch for k in tags.keys(): if k.replace(' ', '') is not '': if '(n)' in k : if tags[k]['position'] == 'last': row = rowgg tmp = self.getTagToPrint(tmp, column = colu,row=row-1, tags=tags,k=k,pageNamber=pageNamber) itedict["CH"] = tmp ElementTree.SubElement(cel.values()[0][0], 'ITEXT', itedict) # origpara = ricel.values()[0][2] # para = cel.values()[0][2] # if origpara: # origpara=origpara[0] # if para: # for t in para: # attria = t.items() # for attrr in attria: # origpara.set(attrr[0],attrr[1]) # else: # paradict = {} # for attrr in origpara.items(): # paradict[attrr[0]] = attrr[1] # ElementTree.SubElement(cel.values()[0][0], 'para', paradict) trai = ricel.values()[0][3] origtrai = cel.values()[0][3] if origtrai: origtrai=origtrai[0] for t in trai: attria = t.items() for attrr in attria: origtrai.set(attrr[0],attrr[1]) else: for t in trai: traidict = {} attria = t.items() for attrr in attria: traidict[attrr[0]] = attrr[1] ElementTree.SubElement(cel.values()[0][0], 'trail', traidict) else: # Qui vengono gestite le tabelle e le celle con tag non iteranti itexts = [x.findall('ITEXT') for x in gruppo["cells"]] pageNamber = int(gruppo["cells"][0].get("OwnPage")) if itexts: for tex in itexts: if type(tex) == type([1,2]): if tex: itext = tex[0] else: continue ch = itext.get('CH') tags = Sla2pdfUtils.findTags(ch) if tags: tmp = ch tagsKeys = tags.keys() for k in tagsKeys: if k.replace(' ', '') == '': continue tmp = self.getTagToPrint(tmp,tags=tags, k=k,pageNamber =pageNamber) if tmp != "": prova = ch.replace(tmp,"") test= prova.encode("utf-8")+" "+ tmp.encode("utf-8") else: test = tmp itext.set('CH',test )