generatereport.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目: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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号