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


Python Canvas.translate方法代码示例

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


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

示例1: piece_stickers

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
def piece_stickers ( pieces, output ):

    c = Canvas ( output, pagesize=letter )
    x_range = range(3)
    y_range = range(10)
    pieceiter = iter(pieces)
    
    last_artist = None

    try:
        piece = pieceiter.next ()
        while True:
            try:
                for y in range(10):
                    for x in range(3):
                        if piece.artist != last_artist and x != 0:
                            continue
                        message = "<b>%s</b><br/><i>%s</i><br/>%s" % ( piece.name, piece.artist.artistname(), piece.media )
                        c.saveState ()
                        c.translate ( (3/16.0 + x * (2+3/4.0)) * inch, (9.5 - y) * inch )
                        text_into_box ( c, message, 0.2, 0.1, 2.475, 0.9, style=piece_sticker_style, escape_text=False, fontSize=12 )
                        c.restoreState ()
                        last_artist = piece.artist
                        piece = pieceiter.next ()
            finally:
                c.showPage ()
    except StopIteration:
        pass
            
    c.save ()
开发者ID:chmarr,项目名称:artshow-fc2013,代码行数:32,代码来源:preprint.py

示例2: test_06_fontsize

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
 def test_06_fontsize(self):
     from reportlab.lib.pagesizes import A4
     from reportlab.pdfgen.canvas import Canvas
     from reportlab.lib.units import inch
     from reportlab.lib.colors import red, magenta
     c = Canvas('demo.pdf', pagesize=A4)
     c.translate(inch, inch)
     c.setFont("Times-Roman", 20)
     c.setFillColor(red)
     c.saveState()
     c.drawCentredString(2.75*inch, 2.5*inch,"Font size excmples")
     c.setFillColor(magenta)
     size = 7
     x = 2.3 * inch
     y = 1.3 * inch
     for line in range(7):
         c.setFont("Helvetica", size)
         c.drawRightString(x, y, "%s points" % size)
         c.drawString(x,y, "test")
         y = y-size*1.2
         size = size+1.5
     c.restoreState()
     c.drawString(0,0, "%s" % c.getAvailableFonts())
     c.showPage()
     c.save()
开发者ID:zenist,项目名称:ZLib,代码行数:27,代码来源:test_pdf.py

示例3: make_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
def make_pdf(outfn, xobjpairs):
    canvas = Canvas(outfn)
    for xobjlist in xobjpairs:
        x = y = 0
        for xobj in xobjlist:
            x += xobj.BBox[2]
            y = max(y, xobj.BBox[3])

        canvas.setPageSize((x,y))

        # Handle blank back page
        if len(xobjlist) > 1 and xobjlist[0] == xobjlist[-1]:
            xobjlist = xobjlist[:1]
            x = xobjlist[0].BBox[2]
        else:
            x = 0
        y = 0

        for xobj in xobjlist:
            canvas.saveState()
            canvas.translate(x, y)
            canvas.doForm(makerl(canvas, xobj))
            canvas.restoreState()
            x += xobj.BBox[2]
        canvas.showPage()
    canvas.save()
开发者ID:kulbirsaini,项目名称:pdfrw-fork,代码行数:28,代码来源:booklet.py

示例4: _get_output_page

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
    def _get_output_page(self, output_infos):
        inch = 72
        buf = io.BytesIO()
        canvas = Canvas(buf, pagesize=(8.5*inch, 11*inch))

        for info in output_infos:
            canvas.saveState()
            x, y = info.translate
            # We flip the y coordinate since that's how PDF programs give us
            # the number of pixels from the top, not the bottom.
            y = 11*inch - y
            canvas.translate(x, y)
            if info.rotate != 0:
                canvas.rotate(info.rotate)

            t = canvas.beginText()
            t.setFont('Courier', 10)
            t.setTextOrigin(0, 0)
            t.textLines(info.text)
            canvas.drawText(t)

            canvas.restoreState()

        canvas.save()
        return PdfFileReader(buf).getPage(0)
开发者ID:feihong,项目名称:ebay-tools,代码行数:27,代码来源:packinginfo.py

示例5: _create_new_canvas

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
        def _create_new_canvas(self):
            pagesize = PAGE_SIZE_MAP[self.pagesize]
            units = UNITS_MAP[self.dest_box_units]
            gc = Canvas(filename=self.filename, pagesize=pagesize)

            width = pagesize[0] * units * inch / 72.0
            height = pagesize[1] * units * inch / 72.0
            x = self.dest_box[0] * units
            y = self.dest_box[1] * units
            w = self.dest_box[2] * units
            h = self.dest_box[3] * units

            if w < 0:
                w += width
            if h < 0:
                h += height

            if w < 0 or h < 0:
                warnings.warn("Margins exceed page dimensions.")
                self.gc = None
                return

            gc.translate(x,y)
            path = gc.beginPath()
            path.rect(0, 0, w, h)
            gc.clipPath(path, stroke=0, fill=0)
            return gc
开发者ID:brycehendrix,项目名称:chaco,代码行数:29,代码来源:pdf_graphics_context.py

示例6: fattura_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
def fattura_pdf(request, id_fattura):
    fattura = Fatture.objects.get(id_fattura=id_fattura)
    # Create the HttpResponse object with the appropriate PDF headers.
    response = HttpResponse(content_type='application/pdf')
    file_name= '%s %s %s' % (fattura.cliente_id.ragione_sociale, fattura.numero_fattura, fattura.data_fattura.isoformat())
    response['Content-Disposition'] = 'filename="%s"' % file_name

    # Create the PDF object, using the response object as its "file."
    canvas = Canvas(response, pagesize=A4)
    canvas.translate(0, 29.7 * cm)
    canvas.setStrokeColorRGB(0.2, 0.2, 0.2)
    canvas.setFillColorRGB(0.2, 0.2, 0.2)
    canvas.setFont('Helvetica', 10)

    draw_header(canvas, fattura)
    draw_invoice_detail(canvas, fattura)
    draw_description(canvas, fattura)
    draw_invoice(canvas, fattura)
    draw_footer(canvas)

    #pdf.restoreState()
    # Close the PDF object cleanly, and we're done.
    canvas.showPage()
    canvas.save()
    return response
开发者ID:MicheleRB,项目名称:studio,代码行数:27,代码来源:views.py

示例7: main

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
def main(infile, outfile, color, font, font_size, portrait, scale, no_times,
         no_weekends, start_monday):
    """
    Weekly schedule typesetter

    Visit <https://github.com/jwodder/schedule> for more information.
    """
    if font in available_fonts():
        font_name = font
    else:
        # Assume we've been given a path to a .ttf file
        font_name = 'CustomFont'
        ### TODO: Use the basename of the filename as the font name?  (Could
        ### that ever cause problems?)
        pdfmetrics.registerFont(TTFont(font_name, font))
    if portrait:
        page_width, page_height = pagesizes.portrait(pagesizes.letter)
    else:
        page_width, page_height = pagesizes.landscape(pagesizes.letter)
    colors = COLORS if color else [GREY]
    if no_weekends:
        week = WEEKDAYS_EN
    elif start_monday:
        week = FULL_WEEK_MON_EN
    else:
        week = FULL_WEEK_EN
    sched = Schedule(week)
    for ev in read_events(infile, colors=colors):
        sched.add_event(ev)
    if outfile is None:
        if infile is sys.stdin:
            outfile_name = '-'
        else:
            outfile_name = str(Path(infile.name).with_suffix('.pdf'))
        outfile = click.open_file(outfile_name, 'wb')
    c = Canvas(outfile, (page_width, page_height))
    c.setFont(font_name, font_size)
    if scale is not None:
        factor = 1 / scale
        c.translate(
            (1-factor) * page_width / 2,
            (1-factor) * page_height / 2,
        )
        c.scale(factor, factor)
    sched.render(
        c,
        x          = inch,
        y          = page_height - inch,
        width      = page_width - 2*inch,
        height     = page_height - 2*inch,
        font_size  = font_size,
        show_times = not no_times,
    )
    c.showPage()
    c.save()
开发者ID:jwodder,项目名称:schedule,代码行数:57,代码来源:pdfschedule.py

示例8: test_04_canvasMethods

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
 def test_04_canvasMethods(self):
     from reportlab.lib.pagesizes import A4
     from reportlab.pdfgen.canvas import Canvas
     from reportlab.lib.units import inch
     c = Canvas('demo.pdf', pagesize=A4)
     c.translate(inch,inch)
     c.setFont("Helvetica", 14)
     c.setAuthor("JY.zenist.song")
     c.setTitle("Hello ReportLib")
     c.drawString(3*inch, 3*inch, "Hello World")
     c.showPage()
     c.save()
开发者ID:zenist,项目名称:ZLib,代码行数:14,代码来源:test_pdf.py

示例9: badge

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
def badge():
    name = request.form['name'][:MAX_CHARS_PER_LINE] if 'name' in request.form else ''
    name2 = request.form['name2'][:MAX_CHARS_PER_LINE] if 'name2' in request.form else ''
    nick = request.form['nick'][:MAX_CHARS_PER_LINE] if 'nick' in request.form else ''
    community = request.form['community'][:MAX_CHARS_PER_LINE] if 'community' in request.form else ''

    pdf = BytesIO()
    c = Canvas(pdf, pagesize=(BADGE_W, BADGE_H))

    c.translate(ORIGIN_X, ORIGIN_Y)

    ico_center = 7*mm
    offset = HEIGHT+2*mm

    c.setFillGray(0.66)
    c.setFont('Awesome', 42)
    c.drawCentredString(ico_center, offset-42*pica/12, '\uf007')
    c.setFont('Awesome', 38)
    c.drawCentredString(ico_center, offset-(2*42+40)*pica/12, '\uf1fa')
    c.drawCentredString(ico_center, offset-(2*42+2*40)*pica/12, '\uf041')

    txt_start = 15*mm

    c.setFillGray(0.0)
    c.setFont('LeagueGothic', 42)
    c.drawString(txt_start, offset-42*pica/12, name)
    c.drawString(txt_start, offset-2*42*pica/12, name2)
    c.setFont('LeagueGothic', 38)
    c.drawString(txt_start, offset-(2*42+40)*pica/12, nick)
    c.drawString(txt_start, offset-(2*42+2*40)*pica/12, community)

    evt_width = 38*pica/12
    evt_start = WIDTH - evt_width

    img_width = 20*mm
    img_start = evt_start - img_width
    c.drawImage(path.join(path.dirname(__file__), 'images/ffrhein_logo_claim_line_rot.png'), img_start, 0, img_width, HEIGHT, mask=None, preserveAspectRatio=True, anchor='c')

    c.rotate(90)
    c.rect(0, -WIDTH, HEIGHT, evt_width, 0, 1)
    c.setFillGray(1.0)
    c.drawCentredString(HEIGHT/2, -WIDTH+MARGIN_R, 'routing days')  

    c.showPage()
    c.save()
    _print(pdf.getvalue())
    pdf.close()

    # response = make_response('Meh')
    # response.headers['Content-Type'] = 'text/plain'
    # return response
    return redirect('/badge/printing.html')
开发者ID:docloy,项目名称:badge-o-matic,代码行数:54,代码来源:webapp.py

示例10: test_07_registerFont

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
    def test_07_registerFont(self):
        from reportlab.lib.pagesizes import A4
        from reportlab.pdfgen.canvas import Canvas
        from reportlab.lib.units import inch
        from reportlab.pdfbase import pdfmetrics
        from reportlab.pdfbase.ttfonts import TTFont

        pdfmetrics.registerFont(TTFont('chsFont', 'STHeiti Light.ttc'))
        c = Canvas('demo.pdf', pagesize=A4)
        c.translate(inch, inch)
        c.setFont('chsFont', 32)
        c.drawString(0,0,"这个字体可以支持中文")
        c.showPage()
        c.save()
开发者ID:zenist,项目名称:ZLib,代码行数:16,代码来源:test_pdf.py

示例11: draw

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
    def draw(self, invoice, stream):
        """ Draws the invoice """
        # embed unicode font
        pdfmetrics.registerFont(
            TTFont('FreeSans', join(STATIC_DIR, 'FreeSans.ttf'))
        )
        addMapping('FreeSans', 0, 0, 'FreeSans')

        self.baseline = -2*cm

        canvas = Canvas(stream, pagesize=A4)
        canvas.setCreator("django-invoice")
        canvas.setAuthor(smart_text(invoice.contractor))
        canvas.setTitle(smart_text(invoice))

        canvas.translate(0, 29.7*cm)
        canvas.setFont(self.FONT_NAME, 10)

        canvas.saveState()
        self.draw_header(invoice, canvas)
        canvas.restoreState()

        canvas.saveState()
        self.draw_subscriber(invoice, canvas)
        canvas.restoreState()

        canvas.saveState()
        self.draw_contractor(invoice, canvas)
        canvas.restoreState()

        canvas.saveState()
        self.draw_info(invoice, canvas)
        canvas.restoreState()

        canvas.saveState()
        self.draw_items(invoice, canvas)
        canvas.restoreState()

        canvas.saveState()
        self.draw_footer(invoice, canvas)
        canvas.restoreState()

        canvas.showPage()
        canvas.save()
        canvas = None
        self.baseline = 0
开发者ID:vandorjw,项目名称:django-invoice,代码行数:48,代码来源:pdf.py

示例12: test_03_draw

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
 def test_03_draw(self):
     from reportlab.lib.pagesizes import A4
     from reportlab.pdfgen.canvas import Canvas
     from reportlab.lib.units import inch
     c = Canvas('demo.pdf', pagesize=A4)
     c.translate(inch,inch)
     c.setFont("Helvetica", 14)
     c.setStrokeColorRGB(0.2,0.5,0.3)
     c.setFillColorRGB(1,0,1)
     c.line(0,0,0,1.7*inch)
     c.line(0,0,1*inch,0)
     c.rect(0.2*inch, 0.2*inch, 1*inch, 1.5*inch,fill=1)
     c.rotate(90)
     c.setFillColorRGB(0,0,0.77)
     c.drawString(0.3*inch, -inch, "Hello World")
     c.showPage()
     c.save()
开发者ID:zenist,项目名称:ZLib,代码行数:19,代码来源:test_pdf.py

示例13: test_05_coordinates

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
 def test_05_coordinates(self):
     from reportlab.lib.pagesizes import A4
     from reportlab.pdfgen.canvas import Canvas
     from reportlab.lib.units import inch
     from reportlab.lib.colors import pink, black, red, blue, green
     c = Canvas('demo.pdf', pagesize=A4)
     c.translate(inch,inch)
     c.setStrokeColor(pink)
     c.grid([1*inch,2*inch,3*inch,4*inch],[0.5*inch, 1*inch, .5*inch, 2*inch, 2.5*inch])
     c.setFont("Times-Roman", 20)
     c.drawString(0,0, "(0,0) the Origin")
     c.drawString(2.5*inch, 1*inch, "(2.5,1) in inches")
     c.drawString(4*inch, 2.5*inch, "(4,2.5)")
     c.setFillColor(red)
     c.rect(0,2*inch,0.2*inch, 0.3*inch, fill=1)
     c.setFillColor(green)
     c.circle(4.5*inch, 0.4*inch, 0.2*inch, fill=1)
     c.showPage()
     c.save()
开发者ID:zenist,项目名称:ZLib,代码行数:21,代码来源:test_pdf.py

示例14: mailing_labels

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
def mailing_labels ( artists, output ):

    c = Canvas(output,pagesize=letter)
    
    label_number = 0
    
    for artist in artists:
        column = label_number%3
        row = label_number/3
        c.saveState ()
        c.translate ( 3/16.0*inch + column*(2+3/4.0)*inch, (9+1/2.0)*inch - row*inch )
        text_into_box ( c, artist.person.get_mailing_label(), 0.1, 0.0, 2.5, 0.85, fontSize=14, style=left_align )
        c.restoreState ()
        
        label_number += 1
        if label_number == 30:
            c.showPage ()
            label_number = 0
            
    if label_number != 0:
        c.showPage ()
    c.save ()
开发者ID:chmarr,项目名称:artshow-fc2013,代码行数:24,代码来源:preprint.py

示例15: bidder_agreement

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import translate [as 别名]
def bidder_agreement(bidder, output):
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont

    pdfmetrics.registerFont(TTFont(*settings.ARTSHOW_BARCODE_FONT))

    c = Canvas(output, pagesize=letter)
    pdf = PdfReader(settings.ARTSHOW_BLANK_BIDDER_AGREEMENT)
    xobj = pagexobj(pdf.pages[0])
    rlobj = makerl(c, xobj)

    c.translate(0, 5.5 * inch)

    c.doForm(rlobj)
    text_into_box(c, u"*P" + unicode(bidder.person.id) + u"*", 3.5, 4.8, 5.5, 5.05, fontSize=14, style=barcode_style)
    text_into_box(c, "Ref. " + unicode(bidder.person.id), 3.5, 4.55, 5.5, 4.75, fontSize=10)

    text_into_box(c, bidder.person.reg_id, 6.2, 1.35, 7.7, 1.6, fontSize=12)

    text_into_box(c, bidder.person.name, 1.3, 1.4, 5.2, 1.7, fontSize=14)
    text_into_box(c, bidder.at_con_contact, 2.1, 0.5, 5.2, 0.8, fontSize=12)

    c.showPage()
    c.save()
开发者ID:chmarr,项目名称:artshow-fc2013,代码行数:26,代码来源:preprint.py


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