Exemple #1
0
    def translate(self):
        self.pageProperties = Sla2pdfUtils.pageProFunc(self.document)
        self.canvas = Canvas(filename = self.pdfFolder + self.pdfFileName + '.pdf', pagesize=(self.pageProperties[0][8],self.pageProperties[0][7]))
        # Page's table
        reiter = False
        self.pdfPage = 0
        for e in xrange(0, self.numPages):
            self.pdfPage = e
            for group in self.tablesProperties:
                self.group = group.keys()[0]
                self.tablesPropertie = group.values()[0]
                try:
                    self.group= self.group.strip().split('%%%')[0]
                except:
                    self.group= self.group.strip()
                if self.group in self.iteratableGroups:
                    colu = int(self.tablesPropertie['columns'])
                    self.tablesPropertie['iterproper'] = self.tablesPropertie['parasobj'][colu:(colu*2)]
                    reiter = True
                cells = int(self.tablesPropertie['cells'])
                # Closing pages (elements of the same page must be near)
                if "noGroup" in self.group and self.tablesPropertie["pfile"] != "" :
                    #print "IMMAGINEEEEEEEEEEEEEEE", self.group, self.tablesPropertie["isTableItem"]
                    self.drawImage(group=self.group) # IMMAGINE
                elif "noGroup" in self.group  and self.tablesPropertie["pfile"] == "":
                    #print "MONOCELLAAAAAAA", self.group, self.tablesPropertie
                    self.drawTable(group =self.group, monocell=True)# MONOCELLA
                else:
#                    print "TABELLAAAAAAAA", self.group, self.tablesPropertie["isTableItem"]
                    self.drawTable(group =self.group, reiter = reiter) # TABELLA
            self.canvas.saveState()
            self.canvas.showPage()
        self.canvas.save()
Exemple #2
0
    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 = self.tablesPropertie['widths']
        heights = self.tablesPropertie['heights']
        cells = int(self.tablesPropertie['cells'])
        columns = int(self.tablesPropertie['columns'])
        rows = int(self.tablesPropertie['rows'])
        sumRows = Sla2pdfUtils.sumRowsFunc(heights,rows)
        sumColumns = Sla2pdfUtils.sumColumnsFunc(widths,columns)

        otherColumn = sumColumns +(int(setconf("Label", "sistemacolonnafrontaline")) or 0)
        sumRows = sumRows + (int(setconf("Label", "sistemarigafrontaline")) or 0)

        self.pageYpos = float(numPages[0].get('PAGEYPOS'))
        self.pageXpos = float(numPages[0].get('PAGEXPOS'))
        self.pageHeight = float(numPages[0].get('PAGEHEIGHT'))
        self.borderTop = float(numPages[0].get('BORDERTOP'))
        self.borderBottom = float(numPages[0].get('BORDERBOTTOM'))
        self.borderLeft = float(numPages[0].get('BORDERLEFT'))
        self.borderRight = float(numPages[0].get('BORDERRIGHT'))
        self.pageWidth = float(numPages[0].get('PAGEWIDTH'))

        realHeightPage = self.pageHeight - self.borderTop - self.borderBottom
        realWidthPage = self.pageWidth - self.borderLeft - self.borderRight
        NumMaxRowLabelForPage = int(realHeightPage/sumRows)
        NumMaxColumnLabelForPage = int(realWidthPage /otherColumn)
        NumMaxLabelForPageTotal = NumMaxRowLabelForPage*NumMaxColumnLabelForPage
        NumLabelInDao = len(self.objects)
        pagesNumber = int((NumLabelInDao/NumMaxLabelForPageTotal)) +1
        self.createPageTag(pagesNumber)
        self.labelObj = self.slaPageObjects()
        op = True
        col = True
        for j in range(1, NumLabelInDao):
            p=r=c = 1
            for pageObject in self.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)

                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(app.get('GROUPS')).strip()
                x = str(10 +j)+ " "
                app.set('GROUPS', str(x))
                #app.set('OwnPage', str(j))
                ## Coordinates
                ypos = app.get('YPOS')
                height = app.get('HEIGHT')
                xpos = app.get('XPOS')
                if (j/NumMaxLabelForPageTotal) >= 1:
                    page = int(j/NumMaxLabelForPageTotal)
                else:
                    page = 0
                if j < NumMaxRowLabelForPage:
                    app.set('YPOS',str(float(ypos)+ sumRows*j))
                elif (j >= NumMaxRowLabelForPage) and (j < NumMaxLabelForPageTotal):
                    app.set('XPOS',str(float(xpos) + float(otherColumn)))
                    app.set('YPOS',str(float(ypos)+(sumRows*(j-NumMaxRowLabelForPage))))
                elif page != 0 and j < ((NumMaxLabelForPageTotal * page) + NumMaxRowLabelForPage):
                    app.set('YPOS',str(float(ypos)+\
                        ((float(self.pageHeight)+float(self.borderTop))*page)+\
                        sumRows*(j-(NumMaxLabelForPageTotal*page))))
                elif page !=0 and j >= (NumMaxLabelForPageTotal * page) +NumMaxRowLabelForPage and j < NumMaxLabelForPageTotal * page +NumMaxLabelForPageTotal:
                    app.set('XPOS',str(float(xpos) + float(otherColumn)))
                    app.set('YPOS',str(float(ypos)+\
                        ((float(self.pageHeight)+float(self.borderTop))*page)+\
                        sumRows*(j-(NumMaxLabelForPageTotal*page)-NumMaxRowLabelForPage)))
                else:
                    print "attenzione oggetto che non ha trovato collocazione"
                self.slaDocumentTag().append(app)
                app = {}
        self.labelSla()
        self.findTablesProperties()