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

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

项目:postix    作者:c3cashdesk    | 项目源码 | 文件源码
def get_default_document(_buffer, footer: str=None) -> BaseDocTemplate:
    def on_page(canvas, doc, footer=footer):
        canvas.saveState()
        if footer:
            canvas.setFontSize(8)
            for i, line in enumerate(footer.split('\n')[::-1]):
                canvas.drawCentredString(PAGESIZE[0] / 2, 25 + (3.5 * i) * mm, line.strip())
            canvas.restoreState()

    doc = BaseDocTemplate(
        _buffer,
        pagesize=PAGESIZE,
        leftMargin=25 * mm,
        rightMargin=20 * mm,
        topMargin=20 * mm,
        bottomMargin=20 * mm,
    )
    frame = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height,
                  leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0, id='normal')
    doc_template = PageTemplate(id='all', pagesize=PAGESIZE, frames=[frame], onPage=on_page)
    doc.addPageTemplates([doc_template])
    return doc
项目:tichu-tournament    作者:aragos    | 项目源码 | 文件源码
def demo1(canvas):
    frame = Frame(
                    2*inch,     # x
                    4*inch,     # y at bottom
                    4*inch,     # width
                    5*inch,     # height
                    showBoundary = 1  # helps us see what's going on
                    )
    bodyStyle = ParagraphStyle('Body', fontName=_baseFontName, fontSize=24, leading=28, spaceBefore=6)
    para1 = Paragraph('Spam spam spam spam. ' * 5, bodyStyle)
    para2 = Paragraph('Eggs eggs eggs. ' * 5, bodyStyle)
    mydata = [para1, para2]

    #this does the packing and drawing.  The frame will consume
    #items from the front of the list as it prints them
    frame.addFromList(mydata,canvas)
项目:mes    作者:osess    | 项目源码 | 文件源码
def __init__(self, out, node, doc):
        if not node.hasAttribute('pageSize'):
            pageSize = (utils.unit_get('21cm'), utils.unit_get('29.7cm'))
        else:
            ps = map(lambda x:x.strip(), node.getAttribute('pageSize').replace(')', '').replace('(', '').split(','))
            pageSize = ( utils.unit_get(ps[0]),utils.unit_get(ps[1]) )
        cm = reportlab.lib.units.cm
        self.doc_tmpl = platypus.BaseDocTemplate(out, pagesize=pageSize, **utils.attr_get(node, ['leftMargin','rightMargin','topMargin','bottomMargin'], {'allowSplitting':'int','showBoundary':'bool','title':'str','author':'str'}))
        self.page_templates = []
        self.styles = doc.styles
        self.doc = doc
        pts = node.getElementsByTagName('pageTemplate')
        for pt in pts:
            frames = []
            for frame_el in pt.getElementsByTagName('frame'):
                frame = platypus.Frame( **(utils.attr_get(frame_el, ['x1','y1', 'width','height', 'leftPadding', 'rightPadding', 'bottomPadding', 'topPadding'], {'id':'text', 'showBoundary':'bool'})) )
                frames.append( frame )
            gr = pt.getElementsByTagName('pageGraphics')
            if len(gr):
                drw = _rml_draw(gr[0], self.doc)
                self.page_templates.append( platypus.PageTemplate(frames=frames, onPage=drw.render, **utils.attr_get(pt, [], {'id':'str'}) ))
            else:
                self.page_templates.append( platypus.PageTemplate(frames=frames, **utils.attr_get(pt, [], {'id':'str'}) ))
        self.doc_tmpl.addPageTemplates(self.page_templates)
项目:tichu-tournament    作者:aragos    | 项目源码 | 文件源码
def test1():
    c  = Canvas('figures.pdf')
    f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
    v = PlatPropFigure1()
    v.captionTextColor = toColor('blue')
    v.captionBackColor = toColor('lightyellow')
    f.addFromList([v],c)
    c.save()
项目:deviation-manual    作者:DeviationTX    | 项目源码 | 文件源码
def __init__(self, filename, **kw):
            m = 2*cm
            cw, ch = (PAGESIZE[0]-2*m)/2., (PAGESIZE[1]-2*m)
            f1 = Frame(m, m+0.5*cm, cw-0.75*cm, ch-1*cm, id='F1',
                leftPadding=0, topPadding=0, rightPadding=0, bottomPadding=0,
                showBoundary=True
            )
            f2 = Frame(cw+2.7*cm, m+0.5*cm, cw-0.75*cm, ch-1*cm, id='F2',
                leftPadding=0, topPadding=0, rightPadding=0, bottomPadding=0,
                showBoundary=True
            )
            apply(BaseDocTemplate.__init__, (self, filename), kw)
            template = PageTemplate('template', [f1, f2])
            self.addPageTemplates(template)
项目:story-card-painter    作者:Cloudist    | 项目源码 | 文件源码
def __paint_story_card(self, story):
        self.story_count += 1

        if self.story_count % 2 == 1:
            if self.story_count > 1:
                self.canvas.showPage()
            x0, y0 = self.padding, self.page_height / 2 + self.padding
            x1, y1 = self.page_width - self.padding, self.page_height - self.padding
        else:
            x0, y0 = self.padding, self.padding
            x1, y1 = self.page_width - self.padding, self.page_height / 2 - self.padding

        # background
        self.canvas.setFillGray(self.lite_gray)
        self.canvas.setLineWidth(4)
        self.canvas.setStrokeGray(self.black)
        self.canvas.rect(x0, y0, x1-x0, y1-y0, stroke=1, fill=1)
        self.canvas.setFillGray(self.white)
        self.canvas.setStrokeGray(self.gray)
        self.canvas.setLineWidth(1)
        self.canvas.rect(x0+20, y0+160, 360, 100, stroke=1, fill=1)
        self.canvas.rect(x0+20, y0+20, 360, 100, stroke=1, fill=1)
        self.canvas.rect(x0+420, y0+210, 100, 80, stroke=1, fill=1)
        self.canvas.rect(x0+420, y0+90, 100, 80, stroke=1, fill=1)

        # keys
        self.setFontSize(16)
        self.canvas.setFillGray(self.black)
        self.canvas.drawString(x0+20, y1-30, 'Backlog item #%s' % story.sid)
        self.canvas.setFillGray(self.gray)
        self.canvas.drawString(x0+20, y0+270, 'How to demo')
        self.canvas.drawString(x0+20, y0+130, 'Notes')
        self.canvas.drawString(x0+420, y0+300, 'Importance')
        self.canvas.drawString(x0+420, y0+180, 'Estimate')

        # values
        self.canvas.setFillGray(self.black)
        self.setFontSize(36)
        self.canvas.drawString(x0+440, y0+240, story.imp)
        self.canvas.drawString(x0+440, y0+120, story.est)

        style = ParagraphStyle('normal', fontName=self.fontname, fontSize=36, leading=40, textColor=[self.black]*3)
        text = [Paragraph(story.name, style)]
        text_inframe = KeepInFrame(360, 60, text)
        frame = Frame(x0+14, y1-95, 360, 60)
        frame.addFromList([text_inframe], self.canvas)

        style = ParagraphStyle('normal', fontName=self.fontname, fontSize=18, leading=24, textColor=[self.black]*3)

        text = [Paragraph(story.demo, style)]
        text_inframe = KeepInFrame(360, 100, text)
        frame = Frame(x0+20, y0+160, 360, 100)
        frame.addFromList([text_inframe], self.canvas)

        text = [Paragraph(story.notes, style)]
        text_inframe = KeepInFrame(360, 100, text)
        frame = Frame(x0+20, y0+20, 360, 100)
        frame.addFromList([text_inframe], self.canvas)
项目:story-card-painter    作者:Cloudist    | 项目源码 | 文件源码
def __paint_story_card(self, story):
        self.story_count += 1

        if self.story_count % 4 == 1 and self.story_count > 1:
            self.canvas.showPage()

        x0, y0 = self.get_origin(self.story_count)
        sx, sy = self.get_size()

        # background
        self.canvas.setFillGray(self.lite_gray)
        self.canvas.setLineWidth(2)
        self.canvas.setStrokeGray(self.black)
        self.canvas.rect(x0, y0, sx, sy, stroke=1, fill=1)
        self.canvas.setLineWidth(1)

        style = ParagraphStyle('normal', fontName=self.fontname, fontSize=18, leading=24, textColor=[self.white]*3)

        # How to demo
        self.canvas.setFillGray(self.gray)
        self.canvas.rect(x0+1, y0+101, sx-2, 80, stroke=0, fill=1)
        self.canvas.setFillGray(self.white)
        text = [Paragraph(story.demo, style)]
        text_inframe = KeepInFrame(sx-2, 80, text)
        frame = Frame(x0+1, y0+101, sx-2, 80)
        frame.addFromList([text_inframe], self.canvas)

        # Notes
        self.canvas.setFillGray(self.gray)
        self.canvas.rect(x0+1, y0+1, sx-2, 80, stroke=0, fill=1)
        self.canvas.setFillGray(self.white)
        text = [Paragraph(story.notes, style)]
        text_inframe = KeepInFrame(sx-2, 80, text)
        frame = Frame(x0+1, y0+1, sx-2, 80)
        frame.addFromList([text_inframe], self.canvas)

        # ID
        self.canvas.setFillGray(self.black)
        self.canvas.rect(x0, y0+248, 50, 30, stroke=0, fill=1)
        self.setFontSize(20)
        self.canvas.setFillGray(self.lite_gray)
        self.canvas.drawString(x0+6, y0+256, '#%s' % story.sid)

        self.setFontSize(13)
        self.canvas.setFillGray(self.gray)
        self.canvas.drawString(x0+6, y0+185, 'How to demo')
        self.canvas.drawString(x0+6, y0+85, 'Notes')

        # Name
        style = ParagraphStyle('normal', fontName=self.fontname, fontSize=28,
                               leading=29, textColor=[self.black]*3)
        text = [Paragraph(story.name, style)]
        text_inframe = KeepInFrame(sx, 47, text)
        frame = Frame(x0, y0+201, sx, 47)
        frame.addFromList([text_inframe], self.canvas)

        # Estimate
        self.canvas.setFillGray(self.gray)
        self.setFontSize(16)
        self.canvas.drawString(x0+344, y0+256, 'Est: %s' % story.est)