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


Python Drawing.drawOn方法代码示例

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


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

示例1: drawOn

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
 def drawOn(self, canvas):
     logo = self.logo
     x, y = logo.x, logo.y
     w, h = logo.width, logo.height
     D = Drawing(w, h)
     D.add(logo)
     D.drawOn(canvas, 0, 0)
开发者ID:roytest001,项目名称:PythonCode,代码行数:9,代码来源:customshapes.py

示例2: TweetsReport

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
class TweetsReport():
    """ Ecrit sur un canvas """
    def __init__(self,pdfPath):
        self.canvas = Canvas(pdfPath)

    def ecrireLegende(self, decalage, year, donnes):
        """ Ecrire la légenge """
        self.canvas.setFont('Times-Bold', 18)
        self.canvas.drawString(70,610 - decalage ,"Année {0}".format(year))
        self.canvas.setFont("Helvetica", 10)
        self.canvas.drawString(420,680 - decalage ,"Janvier : {0}".format(donnes[0]) )
        self.canvas.drawString(420,668 - decalage ,"Février : {0}".format(donnes[1]) )
        self.canvas.drawString(420,656 - decalage ,"Mars : {0}".format(donnes[2]) )
        self.canvas.drawString(420,644 - decalage ,"Avril : {0}".format(donnes[3]) )
        self.canvas.drawString(420,632 - decalage ,"Mai : {0}".format(donnes[4]) )
        self.canvas.drawString(420,620 - decalage ,"Juin : {0}".format(donnes[5]) )
        self.canvas.drawString(420,608 - decalage ,"Juillet : {0}".format(donnes[6]) )
        self.canvas.drawString(420,596 - decalage ,"Août : {0}".format(donnes[7]) )
        self.canvas.drawString(420,584 - decalage ,"Septembre : {0}".format(donnes[8]) )
        self.canvas.drawString(420,572 - decalage ,"Octobre : {0}".format(donnes[9]) )
        self.canvas.drawString(420,560 - decalage ,"Novembre : {0}".format(donnes[10]) )
        self.canvas.drawString(420,548 - decalage ,"Décembre : {0}".format(donnes[11]) )


    def ecrireTitre(self,user):
        """ Ecrire le titre """
        self.canvas.setFont('Times-Bold', 18)
        self.canvas.drawString(50,790,"Cltwit")
        self.canvas.setFont("Helvetica", 14)
        self.canvas.drawString(50,750,"Nombre de tweets envoyés par année et par mois par {0}".format(user))

    def addPie(self,decalage,donnes):
        self.d = Drawing(300, 200)
        self.pc = Pie()
        self.pc.data = donnes
        self.pc.checkLabelOverlap = 1
        self.pc.labels = ['Jan.','Fev.','Mar.','Avr.','Mai.','Juin','Jui.','Aou.','Sept','Oct.','Nov.','Dec.']
        self.pc.x = 20
        self.pc.y = 90
        self.pc.width = 140
        self.pc.height = 140
        n = len(self.pc.data)
        setItems(n,self.pc.slices,'fillColor',pdf_chart_colors)
        self.d.add(self.pc)
        self.d.drawOn(self.canvas, 200, 450 - decalage)

    def NextPage(self):
        """ Créer une nouvelle page """
        self.canvas.showPage()

    def save(self):
        """ Enregistrer """
        self.canvas.save()
开发者ID:Psycojoker,项目名称:cltwit,代码行数:55,代码来源:cltwitreport.py

示例3: generatePdf

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
def generatePdf(description,upc,pages):
    tmpFile = NamedTemporaryFile(delete=False).name
    c=canvas.Canvas(tmpFile,pagesize=letter)
    count = 0
    page = 1

    products = list()
    for i in range(30*pages):
        products.append({"upc":upc, "description":description})

    marginTop = 8.8 * mm
    marginLeft = 4 * mm
    labelHeight = 25.5 * mm
    labelWidth = 67 * mm


    # Assume 10dx5a labels for now.
    finish = False
    while not finish:
        for i in reversed(range(10)):
            for j in range(3):
                try:
                    item = products[count]
                    print item["description"]
                    count = count + 1
                    x = marginLeft + (j*labelWidth)
                    y = marginTop + (i*labelHeight)
                    c.setFillColorCMYK(0,0,0,1)
                    c.setFont("Helvetica",12)
                    c.drawString(x + (10 * mm), y + (21 * mm), item["description"].upper())
                    drawing = Drawing()
                    barcode = Ean13BarcodeWidget()
                    barcode.value = str(int(item["upc"])).zfill(12)
                    barcode.barHeight = 12 * mm
                    barcode.barWidth = 0.95
                    barcode.fontSize = 6
                    drawing.add(barcode)
                    drawing.drawOn(c,x + (10 * mm), y + (8 * mm))
                except:
                    finish = True
        c.showPage()

    c.save()
    response = make_response(open(tmpFile).read())
    response.headers["Content-type"] = "application/pdf"
    return response
开发者ID:doobeh,项目名称:customtags,代码行数:48,代码来源:__init__.py

示例4: _draw_barcode

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
 def _draw_barcode(self, value, barHeight, barWidth):
     """Draw a barcode"""
     barcode = Drawing()
     if barHeight is None:
         barcode.add(BarcodeCode128(
             value=value,
             barWidth=barWidth
         ))
     else:
         barcode.add(BarcodeCode128(
             value=value,
             barHeight=barHeight,
             barWidth=barWidth
         ))
     barcode.drawOn(
         self.canv,
         self.cursor.x * self.unit,
         self.cursor.y * self.unit,
     )
开发者ID:affinitic,项目名称:affinitic.pdf,代码行数:21,代码来源:flowable.py

示例5: symbols

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
def symbols(canv,data):
    '''
    produces filled symbols

    arguments
    n   number of points default 5
    x,y     initial symbol location
    dx      delta x for each new symbol
    dy      delta y for each symbol
    name    symbol name (suitable for makeMarker)
    fillColor   symbol fill colour
    strokeColor symbol stroke colour
    strokeWidth symbol stroke width
    angle   symbol angle
    '''
    args, kw = _evalArgs(data)
    if args:
        raise TypeError('Symbols takes no positional arguments')
    params = dict(
            n=5,
            x='72',
            y='72',
            dx='None',
            dy='0',
            name='StarFive',
            fillColor='yellow',
            strokeColor=None,
            strokeWidth='1',
            angle=0,
            )
    params.update(kw)

    from reportlab.graphics.shapes import Drawing
    from reportlab.graphics.widgets.markers import makeMarker
    from rlextra.rml2pdf.rml2pdf import readLengthOrNone

    name = params['name']
    n = int(params['n'])
    x0 = readLengthOrNone(params['x'])
    y0 = readLengthOrNone(params['y'])
    angle = float(params['angle'])
    size = readLengthOrNone(params['size'])
    strokeWidth = readLengthOrNone(params['strokeWidth'])
    dx = readLengthOrNone(params['dx'])
    if dx is None: dx = 2+1.5*size
    dy = readLengthOrNone(params['dy'])
    strokeColor = _toColor(params['strokeColor'])
    fillColor = _toColor(params['fillColor'])

    D = Drawing()
    for i in range(n):
        m = makeMarker(name)
        m.x = dx*i
        m.y = dy*i
        m.angle = angle
        m.size = size
        m.strokeWidth = strokeWidth
        m.strokeColor = strokeColor
        m.fillColor = fillColor
        D.add(m)

    D.drawOn(canv,x0,y0)
开发者ID:AndyKovv,项目名称:hostel,代码行数:64,代码来源:mymodule.py

示例6: run

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
def run():
    c = reportlab.pdfgen.canvas.Canvas('barcodetest.pdf', pagesize=pagesizes.A4)

    framePage(c, 'Hebi-No-Shisho Barcode Test Page' )
    
    y = 700
    yd = 50
    xb = 40
    xs = 240

    y = y-yd
    mybarcode = code39.Standard39(barWidth=inch * 0.010, value="CD3910", checksum=0)
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard39 10 mil' % mybarcode.encoded)
    
    y = y-yd
    mybarcode = code39.Standard39(barWidth=inch * 0.015, value="CD3915", checksum=0)
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard39 15 mil' % mybarcode.encoded)
    
    y = y-yd
    mybarcode = code39.Standard39(barWidth=inch * 0.020, value="CD3930", checksum=0)
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard39 20 mil' % mybarcode.encoded)
    
    y = y-yd
    mybarcode = code93.Standard93(barWidth=inch * 0.010, value="CD9310")
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard93 10 mil' % mybarcode.encoded)
    
    y = y-yd
    mybarcode = code93.Standard93(barWidth=inch * 0.015, value="CD9315")
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard93 15 mil' % mybarcode.encoded)
    
    y = y-yd
    mybarcode = code93.Standard93(barWidth=inch * 0.020, value="CD9320")
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard93 20 mil' % mybarcode.encoded)
    
    y = y-yd
    mybarcode = code128.Code128(barWidth=inch * 0.010, value="C12810")
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard128 10 mil' % mybarcode.value)
    
    y = y-yd
    mybarcode = code128.Code128(barWidth=inch * 0.015, value="C12815")
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard128 15 mil' % mybarcode.value)
    
    y = y-yd
    mybarcode = code128.Code128(barWidth=inch * 0.020, value="C12820")
    mybarcode.drawOn(c, xb, y)
    c.drawString(xs, y, '%s - Standard128 20 mil' % mybarcode.value)
    
    y = y-yd-10
    mydrawing = Drawing()
    mybarcode = eanbc.Ean13BarcodeWidget(barHeight=inch * 0.5, barWidth=inch * 0.015, value="123456789012")
    mydrawing.add(mybarcode)
    mydrawing.drawOn(c, xb, y)
    c.drawString(xs, y, 'EAN13')
    
    c.save()
开发者ID:Konfuzzyus,项目名称:pybrarius,代码行数:65,代码来源:test.py

示例7: body

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
    def body():
        # Body

        size_y = 0.62
        data = [["Sold", "Cash", "Card", "Contingent", "Reserved", "Expected", "Unsold Reserv."]]
        for cat, value in report_result_dict.iteritems():
            size_y = size_y + 1.86
            """
            if cat == 'all':
                report_cat_name = 'All'
            else:
                report_cat_name = self.report_cat_list[event_id][cat]
            """
            if cat == "all":
                categorie_name = "All"
            else:
                categorie_name = cat_name[cat]

            p = Paragraph('<para alignment="center"><b>' + categorie_name + "</b></para>", styles["Normal"])
            data.append([p, "", "", "", "", "", ""])
            if cat == "all":
                data_for_pie = [
                    value["a_total_sold"],
                    value["a_sold_cash"],
                    value["a_sold_card"],
                    value["a_sold_conti"],
                    value["a_reserved"],
                    value["a_not_visited"],
                ]

            data.append(
                [
                    value["a_total_sold"],
                    value["a_sold_cash"],
                    value["a_sold_card"],
                    value["a_sold_conti"],
                    value["a_reserved"],
                    value["a_total_pre"],
                    value["a_not_visited"],
                ]
            )

            data.append(
                [
                    str(value["m_total_sold"]) + unichr(8364),
                    str(value["m_sold_cash"]) + unichr(8364),
                    str(value["m_sold_card"]) + unichr(8364),
                    "-",
                    str(value["m_reserved"]) + unichr(8364),
                    str(value["m_total_pre"]) + unichr(8364),
                    str(value["m_not_visited"]) + unichr(8364),
                ]
            )

        tstyle = [
            ("INNERGRID", (0, 0), (-1, -1), 0.25, colors.grey),
            ("BOX", (0, 0), (-1, -1), 0.25, colors.black),
            ("ALIGN", (0, 1), (-1, -1), "RIGHT"),
            (
                "COLBACKGROUNDS",
                (0, 0),
                (-1, -1),
                [
                    colors.lightpink,
                    colors.lightpink,
                    colors.lightpink,
                    colors.lightpink,
                    colors.lightyellow,
                    colors.lightgrey,
                    colors.lightyellow,
                ],
            ),
            ("ROWBACKGROUNDS", (0, 1), (-1, -1), [colors.lightslategray, None, None]),
        ]

        t = Table(data)
        t.setStyle(TableStyle(tstyle))
        t.wrapOn(c, 19 * cm, 0 * cm)
        pos_y = 26.5 - size_y
        t.drawOn(c, 1 * cm, pos_y * cm)

        # Price Details
        # size_y = 0.62

        pdata = []
        for cat, value in report_result_dict.iteritems():
            size_y = size_y + 1.86

            if cat == "all":
                pass
            else:
                categorie_name = cat_name[cat]

                p = Paragraph('<para alignment="center"><b>' + categorie_name + "</b></para>", styles["Normal"])
                pdata.append([p])

                data_price_titles = []
                data_price_amount = []
                data_price_total = []
                for prow in p_result:
#.........这里部分代码省略.........
开发者ID:jaques30081983,项目名称:btms_suite,代码行数:103,代码来源:report.py

示例8: testUtf8Canvas

# 需要导入模块: from reportlab.graphics.shapes import Drawing [as 别名]
# 或者: from reportlab.graphics.shapes.Drawing import drawOn [as 别名]
    def testUtf8Canvas(self):
        """Verify canvas declared as utf8 autoconverts.

        This assumes utf8 input. It converts to the encoding of the
        underlying font, so both text lines APPEAR the same."""


        c = Canvas(outputfile('test_pdfbase_encodings_utf8.pdf'))

        c.drawString(100,700, testUTF8)

        # Set a font with UTF8 encoding
        c.setFont('Vera', 12)

        # This should pass the UTF8 through unchanged
        c.drawString(100,600, testUTF8)
        # and this should convert from Unicode to UTF8
        c.drawString(100,500, testUni)


        # now add a paragraph in Latin-1 in the latin-1 style
        p = Paragraph(testUTF8, style=self.styNormal, encoding="utf-8")
        w, h = p.wrap(150, 100)
        p.drawOn(c, 100, 400)  #3
        c.rect(100,300,w,h)

        # now add a paragraph in UTF-8 in the UTF-8 style
        p2 = Paragraph(testUTF8, style=self.styTrueType, encoding="utf-8")
        w, h = p2.wrap(150, 100)
        p2.drawOn(c, 300, 400) #4
        c.rect(100,300,w,h)

        # now add a paragraph in Unicode in the latin-1 style
        p3 = Paragraph(testUni, style=self.styNormal)
        w, h = p3.wrap(150, 100)
        p3.drawOn(c, 100, 300)
        c.rect(100,300,w,h)

        # now add a paragraph in Unicode in the UTF-8 style
        p4 = Paragraph(testUni, style=self.styTrueType)
        p4.wrap(150, 100)
        p4.drawOn(c, 300, 300)
        c.rect(300,300,w,h)

        # now a graphic
        d1 = Drawing(400,50)
        d1.add(Ellipse(200,25,200,12.5, fillColor=None))
        d1.add(String(200,25,testUTF8, textAnchor='middle', encoding='utf-8'))
        d1.drawOn(c, 100, 150)

        # now a graphic in utf8
        d2 = Drawing(400,50)
        d2.add(Ellipse(200,25,200,12.5, fillColor=None))
        d2.add(String(200,25,testUTF8, fontName='Vera', textAnchor='middle', encoding='utf-8'))
        d2.drawOn(c, 100, 100)

        # now a graphic in Unicode with T1 font
        d3 = Drawing(400,50)
        d3.add(Ellipse(200,25,200,12.5, fillColor=None))
        d3.add(String(200,25,testUni, textAnchor='middle'))
        d3.drawOn(c, 100, 50)

        # now a graphic in Unicode with TT font
        d4 = Drawing(400,50)
        d4.add(Ellipse(200,25,200,12.5, fillColor=None))
        d4.add(String(200,25,testUni, fontName='Vera', textAnchor='middle'))
        d4.drawOn(c, 100, 0)

        extracted = extractText(c.getCurrentPageContent())
        self.assertEquals(extracted[0], expectedCp1252)
        self.assertEquals(extracted[1], extracted[2])
        #self.assertEquals(subsetToUnicode(self.vera, extracted[1]), testUni)
        c.save()
开发者ID:JeffBerger,项目名称:solcorporation,代码行数:75,代码来源:test_pdfbase_encodings.py


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