Esempio n. 1
0
    def A4_page_foot(self, canvas, doc):
        canvas.saveState()

        # qrcode
        qrcode = self.codeimg
        qrcode.wrap(3*cm, 3*cm)
        qrcode.drawOn(canvas, doc.width, 1.5*cm)
        # ticket order
        if self.order:
            pr = Paragraph(_('ORDER: %s') % self.order, self.styleL)
            pr.wrap(doc.width, 1*cm)
            pr.drawOn(canvas, doc.leftMargin, 1.5*cm)
        # line
        hr = HRFlowable(width="100%", thickness=0.25, hAlign='CENTER',
                        color=colors.black, vAlign='BOTTOM', dash=None,
                        spaceAfter=5)
        hr.wrap(doc.width, 1*cm)
        hr.drawOn(canvas, doc.leftMargin, 1.5*cm)
        # ticket window code
        pr = Paragraph(self.wcode, self.styleL)
        pr.wrap(doc.width, 1*cm)
        pr.drawOn(canvas, doc.leftMargin, 1.0*cm)
        # code
        pr = Paragraph(self.code, self.styleL)
        pr.wrap(doc.width, 1*cm)
        pr.drawOn(canvas, doc.width, 1.0*cm)

        canvas.restoreState()
Esempio n. 2
0
    def make_pdf(self, data, start_date, end_date, filename, emails):

        width, height = A4
        styles = getSampleStyleSheet()
        styleN = styles["BodyText"]
        styleN.alignment = TA_LEFT
        styleN.fontName = 'Helvetica'
        styleN.textColor = colors.black
        styleBH = styles["Heading3"]
        styleBH.alignment = TA_CENTER
        styleBH.fontName = 'Helvetica'
        styleBH.textColor = colors.darkslategray
        styleTH = styles["Heading1"]
        styleTH.alignment = TA_CENTER
        styleTH.fontName = 'Helvetica'
        styleTH.textColor = colors.darkslateblue
        styleGH = styles["Heading2"]
        styleGH.alignment = TA_CENTER
        styleGH.fontName = 'Helvetica'
        styleGH.textColor = colors.darkslategray
        #styleGH.backColor = colors.lightgrey

        styleNC = styles["BodyText"]
        #styleNC.alignment = TA_CENTER
        styleNC.fontName = 'Helvetica'

        def coord(x, y, unit=1):
            x, y = x * unit, height - y * unit
            return x, y

        def style_row(row_array, style):
            styled_array = []
            for each in row_array:
                styled_array.extend([Paragraph(str(each), style)])
            return styled_array

        c = canvas.Canvas(os.path.join(settings.PDF_REPORTS_DIR, 'gka_sms/') +
                          filename + ".pdf",
                          pagesize=A4)
        #logo
        logo_image = Image("%s/images/akshara_logo.jpg" %
                           settings.STATICFILES_DIRS)
        logo_image.drawOn(c, *coord(14, 3, cm))
        #HR
        hr = HRFlowable(width="80%",
                        thickness=1,
                        lineCap='round',
                        color=colors.lightgrey,
                        spaceBefore=1,
                        spaceAfter=1,
                        hAlign='CENTER',
                        vAlign='BOTTOM',
                        dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 3.2, cm))
        #Headings
        header = Paragraph('GKA SMS Summary<br/><hr/>', styleTH)
        header.wrapOn(c, width, height)
        header.drawOn(c, *coord(0, 4, cm))
        #Date Range
        date_range = Paragraph(
            "From " + start_date.strftime("%d %b, %Y") + " to " +
            end_date.strftime("%d %b, %Y"), styleBH)
        date_range.wrapOn(c, width, height)
        date_range.drawOn(c, *coord(0, 4.5, cm))
        #Details
        styled_data = [style_row(data[0], styleGH)]
        for row in data[1:4]:
            styled_data.append(style_row(row, styleN))

        table_header = Table(styled_data, colWidths=[7 * cm, 5 * cm, 5 * cm])
        table_header.setStyle(
            TableStyle([
                ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                ('BOX', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                ('LINEBELOW', (0, 0), (2, 0), 1.0, colors.darkgrey),
                ('LINEBELOW', (0, 3), (2, 3), 1.0, colors.darkgrey),
            ]))
        table_header.wrapOn(c, width, height)
        table_header.drawOn(c, *coord(1.8, 9, cm))
        #Questions
        styled_data = [
            style_row(['Questions', 'Yes', 'No', 'Yes', 'No'], styleBH)
        ]
        for row in data[4:len(data)]:
            styled_data.append(style_row(row, styleN))

        table = Table(
            styled_data,
            colWidths=[7 * cm, 2.5 * cm, 2.5 * cm, 2.5 * cm, 2.5 * cm])
        table.setStyle(
            TableStyle([
                ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                ('BOX', (0, 0), (-1, -1), 0.25, colors.lightgrey),
                #('LINEBELOW', (0,0), (2, 0), 1.0, colors.green),
            ]))
        table.wrapOn(c, width, height)
        table.drawOn(c, *coord(1.8, 17.5, cm))
        #Footer
        #HR
        hr = HRFlowable(width="80%",
                        thickness=1,
                        lineCap='round',
                        color=colors.lightgrey,
                        spaceBefore=1,
                        spaceAfter=1,
                        hAlign='CENTER',
                        vAlign='BOTTOM',
                        dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 27, cm))
        #Disclaimer
        klp_text = Paragraph(
            "This report has been generated by Karnataka Learning Partnership(www.klp.org.in/gka) for Akshara Foundation.",
            styleN)
        klp_text.wrapOn(c, width, height)
        klp_text.drawOn(c, *coord(1.8, 27.5, cm))

        c.save()
        self.send_email(
            start_date.strftime("%d/%m/%Y") + " to " +
            end_date.strftime("%d/%m/%Y"), filename, emails)
Esempio n. 3
0
    def _vheader(canvas, doc, titulo, logo1=None, logo2=None, marcadeagua=''):
        #print('water en vheader', marcadeagua)
        # Save the state of our canvas so we can draw on it
        #canvas.setStrokeColor(lightgreen)
        canvas.setPageCompression(1)
        #canvas.setStrokeColorCMYK(1, 31, 0, 0)
        #canvas.setStrokeColorRGB(0, 0.7333333333333333, 0.6549019607843137 , 0.7)
        canvas.setStrokeColor(naranja)
        canvas.setLineWidth(1)
        canvas.saveState()
        canvas.setTitle(titulo)
        canvas.setSubject('Pictopartos')
        canvas.setAuthor('Matronas y TCAE del H.U.Miguel Servet. Zaragoza')
        canvas.setCreator('https://pictopartos.es')
        canvas.setKeywords([
            'pictos', 'matronas', 'auxiliares', 'partos', 'arasaac', 'HUMS',
            'TCAE'
        ])
        #canvas.translate(0,doc.height)
        canvas.rotate(-90)
        if logo1:
            #logo_salud = imagen(settings.STATICFILES_DIRS[0]+'/logos/salud.png', 28)
            logo_salud = imagen(logo1, 28)
            logo_salud.drawOn(canvas, -doc.height - doc.topMargin,
                              doc.width + doc.leftMargin + 16)
        if logo2:
            #logo_arasaac = imagen(settings.STATICFILES_DIRS[0]+'/logos/arasaac.png', 28)
            logo_arasaac = imagen(logo2, 28)
            logo_arasaac.drawOn(canvas,
                                -doc.topMargin - logo_arasaac.drawWidth,
                                doc.width + doc.leftMargin + 16)
        styles = getSampleStyleSheet()
        header = Paragraph(titulo, styles['Title'])
        header2 = Paragraph(
            'Pictopartos - Matronas y TCAE del HUMS. Pictogramas de @arasaac',
            styles['Italic'])
        w, h = header.wrap(doc.height, doc.leftMargin)
        header.drawOn(
            canvas, -doc.height - doc.topMargin, doc.width + doc.leftMargin +
            24)  #doc.leftMargin, doc.height + doc.topMargin - h + 12)
        w2, h2 = header2.wrap(doc.height, doc.leftMargin)
        header2.drawOn(
            canvas, -doc.height - doc.topMargin, doc.width + doc.leftMargin +
            4)  #doc.leftMargin, doc.height + doc.topMargin - h + 12)
        hr = HRFlowable(width='100%', thickness=0.2, color=naranja)
        hr.wrap(doc.height, doc.topMargin)
        hr.drawOn(canvas, -doc.height - doc.topMargin,
                  doc.width + doc.leftMargin)

        if marcadeagua:
            #print ('EStoy letra a 50')
            canvas.rotate(90)
            canvas.setFont("Courier-Bold", 46)
            canvas.setFillColor(naranja, 0.25)
            #This next setting with make the text of our
            #watermark gray, nice touch for a watermark.
            #canvas.setFillGray(0.2,0.2)
            #Set up our watermark document. Our watermark
            #will be rotated 45 degrees from the direction
            #of our underlying document.
            canvas.translate(500, 100)
            canvas.rotate(35)
            canvas.drawCentredString(45, 200, marcadeagua)
        canvas.restoreState()
Esempio n. 4
0
    def make_pdf(self, data, start_date, end_date, filename, emails):

        width, height = A4
        styles = getSampleStyleSheet()
        styleN = styles["BodyText"]
        styleN.alignment = TA_LEFT
        styleN.fontName = 'Helvetica'
        styleN.textColor = colors.black
        styleBH = styles["Heading3"]
        styleBH.alignment = TA_CENTER
        styleBH.fontName = 'Helvetica'
        styleBH.textColor = colors.darkslategray
        styleTH = styles["Heading1"]
        styleTH.alignment = TA_CENTER
        styleTH.fontName = 'Helvetica'
        styleTH.textColor = colors.darkslateblue
        styleGH = styles["Heading2"]
        styleGH.alignment = TA_CENTER
        styleGH.fontName = 'Helvetica'
        styleGH.textColor = colors.darkslategray
        #styleGH.backColor = colors.lightgrey

        styleNC = styles["BodyText"]
        #styleNC.alignment = TA_CENTER
        styleNC.fontName = 'Helvetica'
   

        def coord(x, y, unit=1):
            x, y = x * unit, height -  y * unit
            return x, y

        def style_row(row_array, style):
            styled_array = []
            for each in row_array:
                styled_array.extend([Paragraph(str(each),style)])
            return styled_array
       
            
        c = canvas.Canvas(os.path.join(settings.PDF_REPORTS_DIR, 'gka_sms/')+filename+".pdf", pagesize=A4)
        #logo
        logo_image = Image("%s/images/akshara_logo.jpg" % settings.STATICFILES_DIRS) 
        logo_image.drawOn(c, *coord(14, 3, cm))
        #HR
        hr = HRFlowable(width="80%", thickness=1, lineCap='round', color=colors.lightgrey, spaceBefore=1, spaceAfter=1, hAlign='CENTER', vAlign='BOTTOM', dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 3.2, cm))
        #Headings
        header = Paragraph('GKA SMS Summary<br/><hr/>', styleTH)
        header.wrapOn(c, width, height)
        header.drawOn(c, *coord(0, 4, cm))
        #Date Range
        date_range = Paragraph("From " + start_date.strftime("%d %b, %Y") + " to " + end_date.strftime("%d %b, %Y"), styleBH)
        date_range.wrapOn(c, width, height)
        date_range.drawOn(c, *coord(0, 4.5, cm))
        #Details
        styled_data = [style_row(data[0],styleGH)]
        for row in data[1:4]:
            styled_data.append(style_row(row,styleN))

        table_header = Table(styled_data, colWidths=[7 * cm,
                                       5* cm, 5 * cm])
        table_header.setStyle(TableStyle([
                       ('INNERGRID', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       ('BOX', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       ('LINEBELOW', (0,0), (2, 0), 1.0, colors.darkgrey),
                       ('LINEBELOW', (0,3), (2, 3), 1.0, colors.darkgrey),
                       
                    ]))
        table_header.wrapOn(c, width, height)
        table_header.drawOn(c, *coord(1.8, 9, cm))
        #Questions
        styled_data =[style_row(['Questions','Yes','No','Yes','No'],styleBH)] 
        for row in data[4:len(data)]:
            styled_data.append(style_row(row,styleN))
        
        table = Table(styled_data, colWidths=[7 * cm,
                                       2.5 * cm, 2.5 * cm,
                                       2.5 * cm, 2.5 * cm])
        table.setStyle(TableStyle([
                       ('INNERGRID', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       ('BOX', (0,0), (-1,-1), 0.25, colors.lightgrey),
                       #('LINEBELOW', (0,0), (2, 0), 1.0, colors.green),
                       
                    ]))
        table.wrapOn(c, width, height)
        table.drawOn(c, *coord(1.8, 17.5, cm))
        #Footer
        #HR
        hr = HRFlowable(width="80%", thickness=1, lineCap='round', color=colors.lightgrey, spaceBefore=1, spaceAfter=1, hAlign='CENTER', vAlign='BOTTOM', dash=None)
        hr.wrapOn(c, width, height)
        hr.drawOn(c, *coord(1.8, 27, cm))
        #Disclaimer
        klp_text = Paragraph("This report has been generated by Karnataka Learning Partnership(www.klp.org.in/gka) for Akshara Foundation.",styleN)
        klp_text.wrapOn(c, width, height)
        klp_text.drawOn(c, *coord(1.8, 27.5, cm))
        
        c.save()
        self.send_email(start_date.strftime("%d/%m/%Y") + " to " + end_date.strftime("%d/%m/%Y"),filename, emails)