Python reportlab.platypus 模块,Image() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用reportlab.platypus.Image()

项目:geo-hpc    作者:itpir    | 项目源码 | 文件源码
def add_header(self):
        # # aiddata logo
        # logo = self.assets_dir + '/templates/aid_data.png'

        # im = Image(logo, 2.188*inch, 0.5*inch)
        # im.hAlign = 'LEFT'
        # self.Story.append(im)

        # self.Story.append(Spacer(1, 0.25*inch))

        # title
        ptext = '<font size=20>AidData GeoQuery Request Documentation</font>'
        self.Story.append(Paragraph(ptext, self.styles['Center']))


    # report generation info
项目:tambox    作者:joseamaya    | 项目源码 | 文件源码
def tabla_encabezado(self,valorizado):
        sp = ParagraphStyle('parrafos',
                            alignment=TA_CENTER,
                            fontSize=14,
                            fontName="Times-Roman")
        try:
            archivo_imagen = os.path.join(settings.MEDIA_ROOT, str(EMPRESA.logo))
            imagen = Image(archivo_imagen, width=90, height=50, hAlign='LEFT')
        except:
            imagen = Paragraph(u"LOGO", sp)
        if valorizado:
            titulo = Paragraph(u"REGISTRO DEL INVENTARIO PERMANENTE VALORIZADO", sp)
        else:
            titulo = Paragraph(u"REGISTRO DEL INVENTARIO PERMANENTE EN UNIDADES FÍSICAS", sp)

        encabezado = [[imagen,titulo]]
        tabla_encabezado = Table(encabezado, colWidths=[2 * cm, 23 * cm])
        return tabla_encabezado
项目:tambox    作者:joseamaya    | 项目源码 | 文件源码
def tabla_encabezado(self, styles):
        sp = ParagraphStyle('parrafos',
                            alignment=TA_CENTER,
                            fontSize=14,
                            fontName="Times-Roman")
        requerimiento = self.requerimiento
        try:
            archivo_imagen = os.path.join(settings.MEDIA_ROOT, str(EMPRESA.logo))
            imagen = Image(archivo_imagen, width=90, height=50, hAlign='LEFT')
        except:
            print u"Ingresa acá  "
            imagen = Paragraph(u"LOGO", sp)
        nro = Paragraph(u"REQUERIMIENTO DE BIENES Y SERVICIOS<br/>N°" + requerimiento.codigo, sp)
        encabezado = [[imagen, nro, '']]
        tabla_encabezado = Table(encabezado, colWidths=[4 * cm, 11 * cm, 4 * cm])
        tabla_encabezado.setStyle(TableStyle(
            [
                ('ALIGN', (0, 0), (1, 0), 'CENTER'),
                ('VALIGN', (0, 0), (1, 0), 'CENTER'),
            ]
        ))
        return tabla_encabezado
项目:postix    作者:c3cashdesk    | 项目源码 | 文件源码
def scale_image(fileish, width: int) -> Image:
    """ scales image with given width. fileish may be file or path """
    img = utils.ImageReader(fileish)
    orig_width, height = img.getSize()
    aspect = height / orig_width
    return Image(fileish, width=width, height=width * aspect)
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def create_logo(self, absolute_path):
        image = Image(absolute_path)
        image._restrictSize(2.5 * inch, 2.5 * inch)
        return image
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def _header_footer(self, canvas, doc):
        # Save the state of our canvas so we can draw on it
        canvas.saveState()
        styles = getSampleStyleSheet()
        style_right = ParagraphStyle(name='right', parent=styles['Normal'], fontName='Helvetica',
                fontSize=10, alignment=TA_RIGHT)
        # Header


        fieldsight_logo = Image('http://' + self.base_url +'/static/images/fs1.jpg')
        fieldsight_logo._restrictSize(1.5 * inch, 1.5 * inch)


        # headerleft = Paragraph("FieldSight", styles['Normal'])
        headerright = Paragraph(self.project_name, style_right)

        # w1, h1 = headerleft.wrap(doc.width, doc.topMargin)
        w2, h2 = headerright.wrap(doc.width, doc.topMargin)

        textWidth = stringWidth(self.project_name, fontName='Helvetica',
                fontSize=10) 

        fieldsight_logo.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 12)
        headerright.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 20)

        project_logo = Image('http://' + self.base_url + self.project_logo)
        project_logo._restrictSize(0.4 * inch, 0.4 * inch)
        project_logo.drawOn(canvas, headerright.width + doc.leftMargin -0.5 * inch - textWidth, doc.height + doc.topMargin + 10)

        # header.drawOn(canvas, doc.leftMargin + doc.width, doc.height + doc.topMargin +20)

        # Footer
        footer = Paragraph('Page no. '+str(canvas._pageNumber), style_right)
        w, h = footer.wrap(doc.width, doc.bottomMargin)
        footer.drawOn(canvas, doc.leftMargin, h + 40)

        # Release the canvas
        canvas.restoreState()
项目:tambox    作者:joseamaya    | 项目源码 | 文件源码
def tabla_encabezado(self, styles):
        orden_compra = self.orden_compra
        sp = ParagraphStyle('parrafos',
                            alignment = TA_CENTER,
                            fontSize = 14,
                            fontName="Times-Roman")
        try:
            archivo_imagen = os.path.join(settings.MEDIA_ROOT,str(EMPRESA.logo))
            imagen = Image(archivo_imagen, width=90, height=50,hAlign='LEFT')
        except:
            imagen = Paragraph(u"LOGO", sp)

        nro = Paragraph(u"ORDEN DE COMPRA", sp)
        ruc = Paragraph("R.U.C."+EMPRESA.ruc, sp)
        encabezado = [[imagen,nro,ruc],['',u"N°"+orden_compra.codigo,EMPRESA.distrito + " " + orden_compra.fecha.strftime('%d de %b de %Y')]]
        tabla_encabezado = Table(encabezado,colWidths=[4 * cm, 9 * cm, 6 * cm])
        tabla_encabezado.setStyle(TableStyle(
            [
                ('ALIGN',(0,0),(2,1),'CENTER'),
                ('VALIGN',(0,0),(2,0),'CENTER'),
                ('VALIGN',(1,1),(2,1),'TOP'),
                ('SPAN',(0,0),(0,1)),  

            ]
        ))
        return tabla_encabezado
项目:tambox    作者:joseamaya    | 项目源码 | 文件源码
def obtener_firma(self, firma_trabajador):
        p = ParagraphStyle('parrafos',
                           alignment=TA_CENTER,
                           fontSize=8,
                           fontName="Times-Roman")
        if firma_trabajador != '':
            archivo_firma = os.path.join(settings.MEDIA_ROOT, str(firma_trabajador))
            firma = Image(archivo_firma, width=90, height=50, hAlign='CENTER')
        else:
            firma = Paragraph(u"Firma No Encontrada", p)
        return firma
项目:tambox    作者:joseamaya    | 项目源码 | 文件源码
def tabla_encabezado(self, styles):
        movimiento = self.movimiento        
        sp = ParagraphStyle('parrafos',
                            alignment = TA_CENTER,
                            fontSize = 14,
                            fontName="Times-Roman")
        try:
            archivo_imagen = os.path.join(settings.MEDIA_ROOT,str(EMPRESA.logo))
            imagen = Image(archivo_imagen, width=90, height=50,hAlign='LEFT')
        except:
            imagen = Paragraph(u"LOGO", sp)

        if movimiento.tipo_movimiento.incrementa:
            nota = Paragraph(u"NOTA DE INGRESO N°", sp)
        else:
            nota = Paragraph(u"NOTA DE SALIDA N°", sp)
        id_movimiento = Paragraph(movimiento.id_movimiento, sp)
        fecha = Paragraph("FECHA: "+movimiento.fecha_operacion.strftime('%d/%m/%y'), sp)        
        encabezado = [[imagen,nota,fecha],
                      ['',id_movimiento,'']
                      ]
        tabla_encabezado = Table(encabezado,colWidths=[4 * cm, 9 * cm, 6 * cm])
        tabla_encabezado.setStyle(TableStyle(
            [
                ('VALIGN',(0,0),(2,0),'CENTER'),
                ('VALIGN',(1,1),(2,1),'TOP'),                
                ('SPAN',(0,0),(0,1)),                        
            ]
        ))
        return tabla_encabezado
项目:tambox    作者:joseamaya    | 项目源码 | 文件源码
def _header_footer(self, canvas, doc):
        canvas.saveState()
        sp = ParagraphStyle('parrafos',
                            alignment=TA_CENTER,
                            fontSize=14,
                            fontName="Times-Roman")
        try:
            archivo_imagen = os.path.join(settings.MEDIA_ROOT, str(EMPRESA.logo))
            imagen = Image(archivo_imagen, width=90, height=50, hAlign='LEFT')
        except:
            imagen = Paragraph(u"LOGO", sp)
        ruc_empresa = "RUC: " + EMPRESA.ruc
        if self.grupos:
            titulo = Paragraph(u"RESUMEN MENSUAL DE ALMACÉN POR GRUPOS Y CUENTAS", sp)
        else:
            titulo = Paragraph(u"RESUMEN MENSUAL DE ALMACÉN", sp)
        periodo = "PERIODO: " + self.desde.strftime('%d/%m/%Y') + ' - ' + self.hasta.strftime('%d/%m/%Y')
        pagina  = u"Página " + str(doc.page) + " de " + str(self.total_paginas)
        encabezado = [[imagen, titulo, pagina],[ruc_empresa,periodo,""]]
        tabla_encabezado = Table(encabezado, colWidths=[3 * cm, 20 * cm, 3 * cm])
        style = TableStyle(
            [
                ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ]
        )
        tabla_encabezado.setStyle(style)
        tabla_encabezado.wrapOn(canvas, 50, 510)
        tabla_encabezado.drawOn(canvas, 50, 510)
        canvas.restoreState()
项目:tambox    作者:joseamaya    | 项目源码 | 文件源码
def _header(self, canvas, doc):
        canvas.saveState()

        sp = ParagraphStyle('parrafos',
                            alignment=TA_CENTER,
                            fontSize=14,
                            fontName="Times-Roman")
        try:
            archivo_imagen = os.path.join(settings.MEDIA_ROOT, str(EMPRESA.logo))
            imagen = Image(archivo_imagen, width=90, height=50, hAlign='LEFT')
        except:
            imagen = Paragraph(u"LOGO", sp)
        ruc_empresa = "RUC: " + EMPRESA.ruc
        if self.valorizado:
            titulo = Paragraph(u"REGISTRO DEL INVENTARIO PERMANENTE VALORIZADO", sp)
        else:
            titulo = Paragraph(u"REGISTRO DEL INVENTARIO PERMANENTE EN UNIDADES FÍSICAS",sp)
        pagina = u"Página " + str(doc.page) + " de " + str(self.total_paginas)
        encabezado = [[imagen, titulo, pagina], [ruc_empresa, "", ""]]
        tabla_encabezado = Table(encabezado, colWidths=[3 * cm, 20 * cm, 3 * cm])
        style = TableStyle(
            [
                ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ]
        )
        tabla_encabezado.setStyle(style)
        tabla_encabezado.wrapOn(canvas, 50, 510)
        tabla_encabezado.drawOn(canvas, 50, 510)
        canvas.restoreState()
项目:smartschool    作者:asifkodur    | 项目源码 | 文件源码
def draw(self):
        self.canv.saveState()
        self.canv.translate(20,-5)# 23,-10
        self.canv.rotate(90)
        Paragraph.draw(self)

        self.canv.restoreState()




#I = Image('Resources/BS.jpeg')
#I.drawHeight =1*inch
项目:king-phisher-plugins    作者:securestate    | 项目源码 | 文件源码
def get_template(self, template_file, url):
        formatted_time = time.ctime()
        company = self.application.config['mailer.company_name']
        sender = self.application.config['mailer.source_email_alias']

        story = []
        click_me = saxutils.escape(self.config['link_text'])
        link = '<font color=blue><link href="' + url + '">' + click_me + '</link></font>'

        logo_path = self.config['logo']
        if logo_path:
            img = platypus.Image(logo_path, 2 * inch, inch)
            story.append(img)

        style_sheet = styles.getSampleStyleSheet()
        style_sheet.add(styles.ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
        ptext = '<font size=10>' + formatted_time + '</font>'
        story.append(platypus.Spacer(1, 12))
        story.append(platypus.Paragraph(ptext, style_sheet['Normal']))
        story.append(platypus.Spacer(1, 12))
        with open(template_file, 'r') as file_h:
            for line in file_h:
                story.append(platypus.Paragraph(line, style_sheet['Normal']))
        story.append(platypus.Spacer(1, 8))
        story.append(platypus.Paragraph(link, style_sheet['Justify']))
        story.append(platypus.Spacer(1, 12))
        ptext = '<font size=10>Sincerely,</font>'
        story.append(platypus.Paragraph(ptext, style_sheet['Normal']))
        story.append(platypus.Spacer(1, 12))
        ptext = '<font size=10>' + sender + '</font>'
        story.append(platypus.Paragraph(ptext, style_sheet['Normal']))
        story.append(platypus.Spacer(1, 12))
        ptext = '<font size=10>' + company + '</font>'
        story.append(platypus.Paragraph(ptext, style_sheet['Normal']))
        return story
项目:2016.2-SME_UnB    作者:fga-gpp-mds    | 项目源码 | 文件源码
def generatePdf(transductor_id):
    import time
    from reportlab.lib.enums import TA_JUSTIFY
    from reportlab.lib.pagesizes import letter
    from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
    from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
    from reportlab.lib.units import inch

    doc = SimpleDocTemplate("src/report/static/Relatorio"+transductor_id+".pdf",
                            pagesize=letter,
                            rightMargin=72, leftMargin=72,
                            topMargin=72, bottomMargin=18)
    Story = []
    logo = "src/report/static/currentGraphic"+transductor_id+".png"
    logo2 = "src/report/static/voltageGraphic"+transductor_id+".png"
    logo3 = "src/report/static/activePowerGraphic"+transductor_id+".png"
    logo4 = "src/report/static/reactivePowerGraphic"+transductor_id+".png"
    logo5 = "src/report/static/apparentPowerGraphic"+transductor_id+".png"

    magName = "Pythonista"
    issueNum = 12
    subPrice = "99.00"
    limitedDate = "03/05/2010"
    freeGift = "tin foil hat"

    formatted_time = time.ctime()
    full_name = "SME-UnB"
    address_parts = ["Campus Universitario UnB", "Brasilia-DF, 70910-900"]

    im = Image(logo, 8 * inch, 5 * inch)
    im2 = Image(logo2, 8 * inch, 5 * inch)
    im3 = Image(logo3, 8 * inch, 5 * inch)
    im4 = Image(logo4, 8 * inch, 5 * inch)
    im5 = Image(logo5, 8 * inch, 5 * inch)

    Story.append(im)
    Story.append(im2)
    Story.append(im3)
    Story.append(im4)
    Story.append(im5)

    styles = getSampleStyleSheet()
    styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
    ptext = '<font size=12>%s</font>' % formatted_time

    Story.append(Paragraph(ptext, styles["Normal"]))
    Story.append(Spacer(1, 12))

    ptext = '<font size=12>%s</font>' % full_name
    Story.append(Paragraph(ptext, styles["Normal"]))
    for part in address_parts:
        ptext = '<font size=12>%s</font>' % part.strip()
        Story.append(Paragraph(ptext, styles["Normal"]))

    Story.append(Spacer(1, 12))
    Story.append(Spacer(1, 12))
    ptext = '<font size=12>{ % trans Report Energy Monitoring % }</font>'
    Story.append(Paragraph(ptext, styles["Normal"]))

    doc.build(Story)
    return 1
项目:mes    作者:osess    | 项目源码 | 文件源码
def _flowable(self, node):
        if node.localName=='para':
            style = self.styles.para_style_get(node)
            return platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str'})))
        elif node.localName=='name':
            self.styles.names[ node.getAttribute('id')] = node.getAttribute('value')
            return None
        elif node.localName=='xpre':
            style = self.styles.para_style_get(node)
            return platypus.XPreformatted(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str','dedent':'int','frags':'int'})))
        elif node.localName=='pre':
            style = self.styles.para_style_get(node)
            return platypus.Preformatted(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str','dedent':'int'})))
        elif node.localName=='illustration':
            return  self._illustration(node)
        elif node.localName=='blockTable':
            return  self._table(node)
        elif node.localName=='title':
            styles = reportlab.lib.styles.getSampleStyleSheet()
            style = styles['Title']
            return platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str'})))
        elif node.localName=='h1':
            styles = reportlab.lib.styles.getSampleStyleSheet()
            style = styles['Heading1']
            return platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str'})))
        elif node.localName=='h2':
            styles = reportlab.lib.styles.getSampleStyleSheet()
            style = styles['Heading2']
            return platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str'})))
        elif node.localName=='h3':
            styles = reportlab.lib.styles.getSampleStyleSheet()
            style = styles['Heading3']
            return platypus.Paragraph(self._textual(node), style, **(utils.attr_get(node, [], {'bulletText':'str'})))
        elif node.localName=='image':
            return platypus.Image(node.getAttribute('file'), mask=(250,255,250,255,250,255), **(utils.attr_get(node, ['width','height'])))
        elif node.localName=='spacer':
            if node.hasAttribute('width'):
                width = utils.unit_get(node.getAttribute('width'))
            else:
                width = utils.unit_get('1cm')
            length = utils.unit_get(node.getAttribute('length'))
            return platypus.Spacer(width=width, height=length)
        elif node.localName=='pageBreak':
            return platypus.PageBreak()
        elif node.localName=='condPageBreak':
            return platypus.CondPageBreak(**(utils.attr_get(node, ['height'])))
        elif node.localName=='setNextTemplate':
            return platypus.NextPageTemplate(str(node.getAttribute('name')))
        elif node.localName=='nextFrame':
            return platypus.CondPageBreak(1000)           # TODO: change the 1000 !
        else:
            sys.stderr.write('Warning: flowable not yet implemented: %s !\n' % (node.localName,))
            return None