当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.setPageCallBack方法代码示例

本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.setPageCallBack方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.setPageCallBack方法的具体用法?Python Canvas.setPageCallBack怎么用?Python Canvas.setPageCallBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.pdfgen.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.setPageCallBack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makeDocument

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import setPageCallBack [as 别名]
def makeDocument(filename, pageCallBack=None):
    #the extra arg is a hack added later, so other
    #tests can get hold of the canvas just before it is
    #saved
    global titlelist, closeit
    titlelist = []
    closeit = 0

    c = Canvas(filename)
    c.setPageCompression(0)
    c.setPageCallBack(pageCallBack)
    framePageForm(c)  # define the frame form
    framePage(c, 'PDFgen graphics API test script')
    makesubsection(c, "PDFgen", 10 * inch)
    story = []
    #add some flowables
    story.append(box(Paragraph("Champions", styleT)))
    story.append(Paragraph("Philosophizing", styleH))
    story.append(Paragraph("""
    This is a paragraph in <i>Normal</i> style.  We do understand exactly why
    the system hates me.  I really really hate the autocorrect.  I really do
    not mind the tab-complete function, but the rest of this is shit.""",
                           styleN))
    data = [[query("cid"), query("total_price"), query("gross_margin"), '03',
            '04'],
            ['10', '11', '12', '13', '14'],
            ['20', '21', '22', '23', '24'],
            ['30', '31', '32', '33', '34']]
    t = Table(data)
    t.setStyle(TableStyle([('BACKGROUND', (1, 1), (-2, -2), colors.green),
                           ('TEXTCOLOR', (0, 0), (1, -1), colors.red)]))
    story.append(t)
    f = Frame(inch, inch, 6.5 * inch, 9 * inch, showBoundary=0)
    f.addFromList(story, c)
    c.showPage()
# END OF PAGE 1
    framePage(c, 'Line Drawing Styles')
    st = []
    st.append(Spacer(0, 0.5 * inch))
    g = Drawing(3, 4)
    f2 = Frame(inch, inch, 6.5 * inch, 9 * inch, showBoundary=0)
    #St.append(g.add(star(c, title="Title", aka="comments", xcenter=2 * inch,
     #                    ycenter=3 * inch, nvertices=5)))
    chart = VerticalBarChart()
    # Set the starting point to be (0, 0).  Changing this value changes
    # the position that the chart is rendered at within it's 'Drawing'
    # space, which we create below.

    chart.x = 0
    chart.y = 0
    # This determines the width, in centimeters (you could use 'inch'
    # as well) of the chart on the paper, as well as the height.
    chart_width = 5 * inch
    chart_height = 4 * inch
    chart.height = chart_height
    chart.width = chart_width
    # The vertical ticks will be labeled from 0 with a value every
    # 15 units, spaced so that the maximum value is 60.
    chart.valueAxis.valueMin = 0
    chart.valueAxis.valueMax = 60
    chart.valueAxis.valueStep = 15
    # Put the labels at the bottom with an interval of 8 units,
    # -2 units below the axis, rotated 30 degrees from horizontal
    chart.categoryAxis.labels.dx = 8
    chart.categoryAxis.labels.dy = -2
    chart.categoryAxis.labels.angle = 30
    # The text box's NE corner (top right) is located at the above
    # coordinate
    chart.categoryAxis.labels.boxAnchor = 'ne'

    # Our various horizontal axis labels
    catNames = ['Jan-06', 'Feb-06', 'Mar-06', 'Apr-06', 'May-06',
                'Jun-06', 'Jul-06', 'Aug-06']
    chart.categoryAxis.categoryNames = catNames

    # Some random data to populate the chart with.
    chart.data = [(8, 5, 20, 22, 37, 28, 30, 47)]

    # Since the 'Chart' class itself isn't a 'Flowable', we need to
    # create a 'Drawing' flowable to contain it.  We want the basic
    # area to be the same size as the chart itself, so we will
    # initialize it with the chart's size.
    g = Drawing(chart_width, chart_height)
    g.add(chart)

    # Add the Chart containing Drawing to our elements list
    st.append(box(g))
    g.add(star(c, title="Right", aka="comments", xcenter=7 * inch,
               ycenter=7 * inch, nvertices=5))
    g.add(star(c, title="Left", aka="comments", xcenter=3 * inch,
               ycenter=7 * inch, nvertices=6))
    st.append(Spacer(1, 1 * inch))
    st.append(box(Paragraph("""
        Well, its now hard to argue that this is working pretty well.  Possibly
        make some nice output charts, and import an image.""", styleH)))
    f2.addFromList(st, c)
    c.showPage()
    c.save()
    return c
开发者ID:JeffBerger,项目名称:solcorporation,代码行数:101,代码来源:multi_test.py

示例2: makeDocument

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import setPageCallBack [as 别名]
def makeDocument(filename, pageCallBack=None):
    #the extra arg is a hack added later, so other
    #tests can get hold of the canvas just before it is
    #saved
    global titlelist, closeit
    titlelist = []
    closeit = 0
    c = Canvas(filename)
    c.setPageCompression(0)
    c.setPageCallBack(pageCallBack)
    framePageForm(c)  # define the frame form
    framePage(c, 'SBS|Charge-Demo Bid')
    makesubsection(c, "Philosophizing", 10 * inch)
    story = []
    #add some flowables
    story.append(Paragraph("Philosophizing", styleH))
    story.append(Paragraph("""
    This is a paragraph in <i>Normal</i> style.  We do understand exactly why
    the system hates me.  I really really hate the autocorrect.  I really do
    not mind the tab-complete function, but the rest of this is shit.""",
                           styleN))
    # let's move on to the divers table
    diver_table = [['Company', 'Gross Margin', 'Total Price']]
    # this is the header row
    diver_table.append([query("cid"), query("gross_margin"),
                        query("total_price")])
        # these are the other rows
    #add_table(diver_table, TABLE_WIDTH)
    #add_table(diver_table, TABLE_WIDTH)
    data = [[query("cid"), query("total_price"), query("gross_margin"), '03',
            '04'],
            ['10', '11', '12', '13', '14'],
            ['20', '21', '22', '23', '24'],
            ['30', '31', '32', '33', '34']]
    t = Table(diver_table)
    #t.setStyle(TableStyle([('BACKGROUND', (1, 1), (-2, -2), colors.green),
    #                       ('TEXTCOLOR', (0, 0), (1, -1), colors.red)]))
    table_style = [
        ('ALIGN', (0, 0), (-1, -1), 'LEFT'),
        ('VALIGN', (0, 0), (-1, -1), 'TOP'),
        ('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'),
        ('LINEBELOW', (0, 0), (-1, 0), 1, colors.black),
        ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor('#C0C0C0')),
        ('ROWBACKGROUNDS', (0, 1), (-1, -1), [colors.white,
         colors.HexColor('#E0E0E0')])
    ]
    t.setStyle(TableStyle(table_style))
    t2 = Table(data)
    t2.setStyle(TableStyle(table_style))
    story.append(Paragraph("Table of imported data", styleH))
    makesubsection(c, "Table", 9 * inch)
    story.append(t)
    story.append(t2)
    t = Table([[u'Corporate Assets', 'Amount'],
               ['Fixed Assets', '1,234,567.89'],
               ['Company Vehicle', '1,234.8901'],
               ['Petty Cash', '42'],
               [u'Intellectual Property\u00ae', query("total_price")],
               ['Overdraft', '(12,345)'],
               ['Boardroom Flat Screen', '60 inches'],
               ['Net Position', 'Moon Base']
               ],
              [144, 72])

    ts = TableStyle([  # first the top row
        ('ALIGN', (1, 1), (-1, -1), 'CENTER'),
        ('LINEABOVE', (0, 0), (-1, 0), 2, colors.purple),
        ('LINEBELOW', (0, 0), (-1, 0), 1, colors.purple),
        ('FONT', (0, 0), (-1, 0), 'Times-Bold'),

        #bottom row has a line above, and two lines below
        ('LINEABOVE', (0, -1), (-1, -1), 1, colors.purple),
        # last 2 are count, sep
        ('LINEBELOW', (0, -1), (-1, -1), 0.5, colors.purple,
         1, None, None, 4, 1),
        ('LINEBELOW', (0, -1), (-1, -1), 1, colors.red),
        ('FONT', (0, -1), (-1, -1), 'Times-Bold'),

        #numbers column
        ('ALIGN', (1, 1), (-1, -1), 'DECIMAL'),
        ('RIGHTPADDING', (1, 1), (-1, -1), 36),
        ('TEXTCOLOR', (1, 4), (1, 4), colors.red),

        #red cell
    ]
    )

    t.setStyle(ts)
    story.append(t)
    story.append(Spacer(36, 36))

    a = Image("SBSchargeLogo.jpg")
    a.drawHeight = 0.5 * inch
    a.drawWidth = 2 * inch
    #c.translate(0.8 * inch, 9.6 * inch)
    #c.rotate(90)
    story.append(a)
    #c.setPageRotation(0)
    #instance = HandAnnotation()
    #instance.wrap()
#.........这里部分代码省略.........
开发者ID:JeffBerger,项目名称:solcorporation,代码行数:103,代码来源:SBSbid.py


注:本文中的reportlab.pdfgen.canvas.Canvas.setPageCallBack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。