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


Python Canvas.drawCentredString方法代码示例

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


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

示例1: generateNumberedPages

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
def generateNumberedPages(numPages, pageSize, orientation, bgColor, outPath):
    "Generate a 10 page document with one big number per page."
    
    if orientation == "landscape":
        pageSize = landscape(pageSize)
    canv = Canvas(outPath, pagesize=pageSize)

    for i in range(numPages):
        canv.setFont("Helvetica", 500)
        text = u"%s" % i
        if i % 2 == 0:
            canv.setStrokeColor(bgColor)
            canv.setFillColor(bgColor)
            canv.rect(0, 0, pageSize[0], pageSize[1], stroke=True, fill=True)
            canv.setFillColor(black)
        elif i % 2 == 1:
            canv.setStrokeColor(black)
            canv.setFillColor(black)
            canv.rect(0, 0, pageSize[0], pageSize[1], stroke=True, fill=True)
            canv.setFillColor(bgColor)
        if orientation == "portrait":
            canv.drawCentredString(pageSize[0]/2.0, pageSize[1]*0.3, u"%s" % i) 
        elif orientation == "landscape":
            canv.drawCentredString(pageSize[0]/2.0, pageSize[1]*0.21, u"%s" % i) 
        canv.showPage()
        
    canv.save() 
开发者ID:nunb,项目名称:pdfnup,代码行数:29,代码来源:genpdf.py

示例2: main

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
def main(argv):
    global X, Y, Title
    if len(argv) != 2:
        print __doc__
        sys.exit(2)
    c = Canvas(argv[1], pagesize=pageSize, pageCompression=0)
    c.setFont(fontName, fontSize)

    init()
    X = 0
    Y = 0
    execfile(argv[0], globals())
    init()
    if Title:
        print "title", Title
        c.drawCentredString(pageSize[0] / 2, pageSize[1] - (margins.top * inch * 0.65), Title)
    X = startX
    Y = startY
    for chart in Charts:
        x = chart.fx
        y = chart.fy
        if not x and not y:
            x = X
            y = Y
        chart.draw(c, x, y)
        over()

    c.showPage()
    c.save()
开发者ID:dirck,项目名称:pytabla,代码行数:31,代码来源:pyneck.py

示例3: draw_label

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
    def draw_label(self, c: Canvas, col: int, row: int, redemption_code: str):
        x = self.left_margin + (col + 0.5) * self.label_width + col * self.inner_margin
        y = self.page_height - self.top_margin - (row + 0.5) * self.label_height

        # Drawing label bounds helps when adjusting layout. Not for production.
        # self.draw_label_bounds(c, x, y)

        c.setFont("Courier-Bold", 13)
        c.drawString(x - 80, y + 14, redemption_code)

        c.setFont("Helvetica", 10)

        # Space to enter redemption month and day.
        p = c.beginPath()
        p.moveTo(x + 20, y + 12)
        p.lineTo(x + 45, y + 12)
        p.moveTo(x + 55, y + 12)
        p.lineTo(x + 80, y + 12)
        p.close()
        c.drawPath(p)
        c.drawCentredString(x + 15, y + 16, 'm:')
        c.drawCentredString(x + 50, y + 16, 'd:')

        # Space to enter redeemer's email address.
        p = c.beginPath()
        p.moveTo(x - 80, y - 14)
        p.lineTo(x + 80, y - 14)
        p.close()
        c.drawPath(p)
        c.drawCentredString(x, y - 24, 'email address')
开发者ID:adrianboyko,项目名称:xerocraft-django,代码行数:32,代码来源:gengiftcards.py

示例4: test_06_fontsize

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [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

示例5: generate_pages

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
def generate_pages(card_sizes,cards, filename="placecards.pdf", custom_font = None):
    pagesize = pagesizes.portrait( ( 8.5 * pagesizes.inch, 11 * pagesizes.inch))
    pdf = Canvas(filename, pagesize=pagesize,pdfVersion=(1,4))
    pdf.setAuthor('placecardboardgenerate.py')
    pdf.setSubject('wedding placecards')
    pdf.setTitle('Placecards for Wedding Reception')
    pdf.setKeywords(('wedding', 'placecards'))
    if custom_font is not None:
        pdf.setFont(custom_font,14)#FIXME don't hardcode font size
            
    adjusted_card_sizes = (card_sizes[0] * pagesizes.inch, card_sizes[1] * pagesizes.inch)
    card_printer = CardPrinter(pagesize,adjusted_card_sizes)

    (cardsPerRow,rowsPerPage) = (card_printer.cards_per_row, card_printer.cards_per_column)

    (page_width, page_height) = pagesize

    groupedCards = group_cards(cards, cardsPerRow, rowsPerPage)
    for (page_index,pageOfCards) in enumerate(groupedCards):
        if custom_font is not None:
            pdf.setFont(custom_font,14)#FIXME don't hardcode font size
        for (row_index,rowOfCards) in enumerate(pageOfCards):
            for (column_index,card) in enumerate(rowOfCards):
                card_printer.print_on_front_page(pdf,card,row_index, column_index)
        pdf.drawCentredString(page_width/2.0,20,"front of page %i" % (page_index + 1))
        pdf.showPage()
        if custom_font is not None:
            pdf.setFont(custom_font,14)#FIXME don't hardcode font size
        for (row_index,rowOfCards) in enumerate(pageOfCards):
            for (column_index,card) in enumerate(rowOfCards):
                card_printer.print_on_back_page(pdf,card,row_index, column_index)                
        pdf.drawCentredString(page_width/2.0,20,"back of page %i" % (page_index + 1))
        pdf.showPage()

    pdf.save()
开发者ID:phillipgreenii,项目名称:photoplacecardboard,代码行数:37,代码来源:placecardboardgenerater.py

示例6: test

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
def test():
    """Test this."""
    from reportlab.pdfgen.canvas import Canvas
    from reportlab.lib import pagesizes

    canvas = Canvas("labels.pdf", pagesize=pagesizes.A4)
    canvas.setFont("Helvetica", 30)
    (width, height) = pagesizes.A4
    canvas.drawCentredString(width / 2.0, height - 4 * cm, "Sample LTO labels")
    xpos = xorig = 2 * cm
    ypos = yorig = 2 * cm
    colwidth = 10 * cm
    lineheight = 3.9 * cm
    count = 1234
    BaseLTOLabel("RL", count, "3").drawOn(canvas, xpos, ypos)
    ypos += lineheight
    count += 1
    BaseLTOLabel("RL", count, "3", border=0.0125).drawOn(canvas, xpos, ypos)
    ypos += lineheight
    count += 1
    VerticalLTOLabel("RL", count, "3").drawOn(canvas, xpos, ypos)
    ypos += lineheight
    count += 1
    VerticalLTOLabel("RL", count, "3", border=0.0125).drawOn(canvas, xpos, ypos)
    ypos += lineheight
    count += 1
    VerticalLTOLabel("RL", count, "3", colored=True).drawOn(canvas, xpos, ypos)
    ypos += lineheight
    count += 1
    VerticalLTOLabel("RL", count, "3", border=0.0125, colored=True).drawOn(canvas, xpos, ypos)
    canvas.showPage()
    canvas.save()
开发者ID:jwheare,项目名称:digest,代码行数:34,代码来源:lto.py

示例7: generateOfficePDF

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
 def generateOfficePDF(self,response):
     #Attach name.pdf file to responses content disposition
     response['Content-Disposition'] = 'attachment; filename=office.pdf'
     
     #Create empty pdf document, hook pdf with response
     pdf = Canvas(response) 
     
     #Get Todays Events
     brains = sorted(util.gatherTodaysEvents(self), key=attrgetter('location')) #so awesome, sorts on any attribute!
     brains = sorted(brains, key=attrgetter('start')) #even better a secondary sort.
     
     #Header: Title Information and Settings
     pdf.setFont("Helvetica-Bold", 12)
     pdf.setStrokeColorRGB(0, 0, 0) #sets Line/Rectangle Colors
     
     #Header Left Title
     if brains != None and len(brains) > 0:
         pdf.drawString(15, 810, DateTime(brains[0].start).strftime("%A, %B %d, %Y") + " Schedule")
     else:
         pdf.drawString(15, 810, "No Groups scheduled for " + datetime.datetime.now().strftime("%A, %B %d, %Y"))
         
     #Header Right Title
     pdf.drawRightString(575, 810, "GroupFinder")
     
     #Body: List of Groups and Settings
     index = 792 #Pixel Index, starting at the top of the pdf page
     page = 1 #Page Number
     
     for brain in brains:
         pdf.setFont("Helvetica", 12)
         pdf.setStrokeColorRGB(0, 0, 0) #sets Line/Rectangle Colors
         pdf.rect(10, index-20, 575, 30, stroke=1, fill=0) #Rectangle around each Group
         pdf.drawString(15, index-3, brain.Title) #Group Description
         
         l = self.locationLookup(brain.location)
         pdf.drawString(15, index-15, DateTime(brain.start).strftime("%I:%M %p") + 
                                      " - " + DateTime(brain.end).strftime("%I:%M %p") +
                                      " in " + l['Name']) 
         index -= 30 #Move Pixel Index downwards
         
         #Reach Bottom of page?  Creates New Page.
         if index < 30:
             pdf.drawString(15, 5, "Page " + str(page))#add page number pages
             pdf.drawCentredString(300, 5, "Created on " + datetime.datetime.now().strftime("%m/%d/%Y at %I:%M %p"))
             page+=1
             index = 792
             pdf.showPage() #next page
     
     #add page number pages
     pdf.drawString(15, 5, "Page " + str(page))
     
     #add date PDF was created
     pdf.drawCentredString(300, 5, "Created on " + datetime.datetime.now().strftime("%m/%d/%Y at %I:%M %p"))
                     
     pdf.showPage() #next page, finalize last page.
     
     pdf.save() #save the pdf content
     return response #return response with hooked pdf.
开发者ID:uwosh,项目名称:uwosh.librarygroupfinder,代码行数:60,代码来源:print.py

示例8: _on_other_page

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
    def _on_other_page(self, canvas: Canvas, doc):
        canvas.saveState()
        canvas.setFont('OpenSans', 8)
        canvas.drawRightString(self.pagesize[0] - 20 * mm, 10 * mm, pgettext("invoice", "Page %d") % (doc.page,))

        for i, line in enumerate(self.invoice.footer_text.split('\n')[::-1]):
            canvas.drawCentredString(self.pagesize[0] / 2, 25 + (3.5 * i) * mm, line.strip())

        canvas.restoreState()
开发者ID:FlaviaBastos,项目名称:pretix,代码行数:11,代码来源:invoice.py

示例9: generateEntrancePDF

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
    def generateEntrancePDF(self,response):
        #Attach name.pdf file to responses content disposition
        response['Content-Disposition'] = 'attachment; filename=entrance.pdf'
        
        #Create empty pdf document, hook pdf with response
        pdf = Canvas(response)



        pdf.setFillColor(colors.black) #sets Line/Rectangle Colors
        pdf.roundRect(10, 755, 575, 75, 10, 1, 0)
        pdf.setFont("Helvetica-Bold", 40)
        pdf.setStrokeColorRGB(0, 0, 0) #sets Line/Rectangle Colors
        pdf.drawCentredString(300, 790, "GroupFinder")
        pdf.setFont("Helvetica-Bold", 20)
        pdf.drawString(15, 765, "The following spaces are reserved during scheduled hours")

        
        pdf.drawCentredString(300,725, datetime.datetime.now().strftime("%A, %B %d, %Y"))

        #Get Todays Events
        brains = sorted(util.gatherTodaysEvents(self), key=attrgetter('start','Title')) 
       
        index = 700
        i = 0
        for brain in brains:
            pdf.rect(45, index-30, 510, 42, stroke=1, fill=0) #Schedule List Rectangles
            if util.isPublic(self,brain.id):
                title = brain.Title
            else:
                title = "Private Group"
                
            pdf.setFont("Helvetica-Bold", 17)
            pdf.drawString(50, index-5, DateTime(brain.start).strftime("%I:%M %p").lower() +
                                        " - " + DateTime(brain.end).strftime("%I:%M %p").lower() +
                                        " : " + title)
            pdf.setFont("Helvetica", 17)
            l = self.locationLookup(brain.location)
            pdf.drawString(50, index-25, "Location: " + l['Name'] + " - " + l['DirectionsShort'])
            
            index -= 42
            i += 1
            if i == 13:
                pdf.setFont("Helvetica", 17)
                pdf.drawCentredString(300, index-5, "See Website For More Study Groups!")
                break
        
        pdf.setFont("Helvetica-Bold", 28)
        pdf.drawCentredString(300, 90, "Use GroupFinder to Reserve a Study Space.")
        pdf.setFont("Helvetica", 24)
        pdf.drawCentredString(300, 60, "http://www.uwosh.edu/library/groupfinder")
        
        pdf = self.tableFooter(pdf)
        
        pdf.showPage() #next page, finalize last page.
        pdf.save() #save the pdf content
        return response #return response with hooked pdf.
开发者ID:uwosh,项目名称:uwosh.librarygroupfinder,代码行数:59,代码来源:print.py

示例10: dumpttf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
def dumpttf(fn, fontName=None, verbose=0):
    """dump out known glyphs from a ttf file"""
    import os

    if not os.path.isfile(fn):
        raise IOError('No such file "%s"' % fn)
    from reportlab.pdfbase.pdfmetrics import registerFont, stringWidth
    from reportlab.pdfbase.ttfonts import TTFont
    from reportlab.pdfgen.canvas import Canvas

    if fontName is None:
        fontName = os.path.splitext(os.path.basename(fn))[0]
    dmpfn = "%s-ttf-dump.pdf" % fontName
    ttf = TTFont(fontName, fn)
    K = list(ttf.face.charToGlyph.keys())
    registerFont(ttf)
    c = Canvas(dmpfn)
    W, H = c._pagesize
    titleFontSize = 30  # title font size
    titleFontName = "Helvetica"
    labelFontName = "Courier"
    fontSize = 10
    border = 36
    dx0 = stringWidth("12345: ", fontName, fontSize)
    dx = dx0 + 20
    dy = 20
    K.sort()
    y = 0
    page = 0
    for i, k in enumerate(K):
        if y < border:
            if page:
                c.showPage()
            page += 1
            y = H - border - titleFontSize
            c.setFont(titleFontName, titleFontSize)
            c.drawCentredString(W / 2.0, y, "TrueType Font %s Page %d" % (fontName, page))
            y -= 0.2 * titleFontSize + dy
            x = border
        c.setFont(labelFontName, 10)
        c.drawString(x, y, "%5.5x:" % k)
        c.setFont(fontName, 10)
        c.drawString(x + dx0, y, chr(k).encode("utf8"))
        x += dx
        if x + dx > W - border:
            x = border
            y -= dy
    c.showPage()
    c.save()
    if verbose:
        print('Font %s("%s") has %d glyphs\ndumped to "%s"' % (fontName, fn, len(K), dmpfn))
开发者ID:FatihZor,项目名称:infernal-twin,代码行数:53,代码来源:dumpttf.py

示例11: test0

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
    def test0(self):
        "A basic document drawing some strings"

        # if they do not have the Japanese font files, go away quietly
        from reportlab.pdfbase.cidfonts import UnicodeCIDFont, findCMapFile


        pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))

        c = Canvas(outputfile('test_multibyte_chs.pdf'))
        c.setFont('Helvetica', 30)
        c.drawString(100,700, 'Simplified Chinese Font Support')


        c.setFont('Helvetica', 10)
        c.drawString(100,680, 'Short sample: "China - Zhang Ziyi"  (famous actress)')
        # the two typefaces

        hBoxText('\u4e2d\u56fd - \u7ae0\u5b50\u6021',
                 c,
                 100,
                 660,
                 'STSong-Light',
                 )


        c.setFont('Helvetica',10)
        c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
        c.showPage()

##        # full kuten chart in EUC
##        c.setFont('Helvetica', 18)
##        c.drawString(72,750, 'Characters available in GB 2312-80, EUC encoding')
##        y = 600
##        enc = 'GB_EUC_H'
##        for row in range(1, 95):
##            KutenRowCodeChart(row, 'STSong-Light',enc).drawOn(c, 72, y)
##            y = y - 125
##            if y < 50:
##                c.setFont('Helvetica',10)
##                c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
##                c.showPage()
##                y = 700
##
        c.save()
        if VERBOSE:
            print('saved '+outputfile('test_multibyte_chs.pdf'))
开发者ID:wolf29,项目名称:EG-notifications,代码行数:49,代码来源:test_multibyte_chs.py

示例12: generate_key

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
def generate_key(verticalCardsCount,horizontalCardsCount,cards, filename="key.pdf", page_margins = 4 * (0.5 * pagesizes.inch, )):
    (page_margin_top, page_margin_left, page_margin_bottom, page_margin_right) = page_margins
    padding = 0.0625 * pagesizes.inch

    spaces = (verticalCardsCount * horizontalCardsCount) * [None,]
    for card in cards:
        spaces[card.position] = card

    pagesize = pagesizes.landscape( ( 8.5 * pagesizes.inch, 11 * pagesizes.inch))
    pdf = Canvas(filename, pagesize=pagesize, pdfVersion=(1,4))
    pdf.setAuthor('placecardboardgenerate.py')
    pdf.setSubject('wedding placecards key')
    pdf.setTitle('Key for Placecards for Wedding Reception')
    pdf.setKeywords(('wedding', 'placecards'))

    (page_width, page_height) = pagesize

    pdf.drawCentredString(page_width/2.0,20,"key of place cards")

    thumbnail_width = ((page_width - page_margin_left - page_margin_right) - (padding * (horizontalCardsCount - 1))) / horizontalCardsCount
    thumbnail_height = ((page_height - page_margin_top - page_margin_bottom) - (padding * (verticalCardsCount - 1))) / verticalCardsCount


    x_margin = page_margin_left
    x_offset = thumbnail_width + padding
    y_margin = page_margin_top
    y_offset = thumbnail_height + padding


    for row_index in range(verticalCardsCount):
        for column_index in range(horizontalCardsCount):
            position = (row_index * horizontalCardsCount) +  column_index
            card = spaces[position]
            (card_x, card_y) = \
                 (x_margin + (x_offset * column_index),\
                  (page_height - thumbnail_height) - (y_margin + (y_offset * row_index)))
            
            if card is not None:
                pdf.drawImage(card.image, card_x, card_y, width = thumbnail_width, height = thumbnail_height)
                pdf.drawCentredString(card_x + thumbnail_width/2.0,card_y + thumbnail_height/2.0, str(card.position))
    
    pdf.showPage()
    pdf.save()
开发者ID:phillipgreenii,项目名称:photoplacecardboard,代码行数:45,代码来源:placecardboardgenerater.py

示例13: badge

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [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

示例14: __init__

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
class DesignShirtsFromCalifornia:
  CHICAGO_HEADLINE=["ThoughtWorks Chicago", "Bringing it since 1992", "CHICAGO", "Rainey's People"]
  ADJECTIVES=["Awesomist", "Best looking", "Happiest", "Legendary", "Transparent", "Shiny", "Dangerous", "Fastest"]
  NOUNS=["Chicagoans", "Agilistas", "Wonderlic Masters", "Bears Fans"]

  ATTRIBUTION="Designed by ThoughtWorks in California"
  GIT_REF="Fork me on Github https://github.com/jawspeak/tw-california-tshirt-generator"

  def __init__(self, output_filename):
    self.pdf = Canvas(output_filename, pagesize = LETTER)
#    self.headlines =

  def draw(self):
    for image in glob.glob('awesomeness/*.[jpg|png|gif]*'):
      self._draw_page(image)
    self.pdf.save()

  def _draw_page(self, image):
    self.pdf.setFillColor(colors.black)
    # To have a higher resolution for printing export the image as a higter resolution image which is then reduced
    self.pdf.drawImage(image, 2.25 * inch, 3.7 * inch, width=300, height=300, preserveAspectRatio=True)

    height = 8
#    print self.pdf.getAvailableFonts()
    self.pdf.setFont("Times-Bold", 28)
    random.shuffle(self.CHICAGO_HEADLINE, random.random)
    self.pdf.drawCentredString(4.25* inch, height*inch, self.CHICAGO_HEADLINE[0].encode('latin-1'))

    self.pdf.setFont("Times-Italic", 16)
    if len(image.split('=')) == 2:
      self.pdf.drawCentredString(4.25* inch, (height - 4.5)* inch, image.split('=')[1].split('.')[0].encode('latin-1'))
    else:
      random.shuffle(self.ADJECTIVES, random.random)
      random.shuffle(self.NOUNS, random.random)
      flattering_tagline = "Home of the %s %s!" % (', '.join(self.ADJECTIVES[:2]), self.NOUNS[0])
      self.pdf.drawCentredString(4.25* inch, (height - 4.5)* inch, flattering_tagline.encode('latin-1'))

    self.pdf.setFont("Times-Italic", 10)
    self.pdf.drawCentredString(4.25 * inch, (height - 4.8) * inch, self.ATTRIBUTION)
    self.pdf.drawCentredString(4.25 * inch, (height - 4.95) * inch, self.GIT_REF)

    self.pdf.showPage()
开发者ID:jawspeak,项目名称:tw-california-tshirt-generator,代码行数:44,代码来源:design_shirts_from_california.py

示例15: genTestFile

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawCentredString [as 别名]
def genTestFile(path, numPages):
    "Generate a PDF doc with *very* big page numbers on all pages."
    
    size = landscape(A4)
    canv = Canvas(path, pagesize=size)
    for i in range(numPages):
        canv.setFont("Helvetica", size[1]*1.2)
        x, y = size[0]/2.0, size[1]*0.1
        text = u"%s" % i
        if i % 2 == 1:
            canv.setStrokeColor(black)
            canv.setFillColor(black)
            canv.rect(0, 0, size[0], size[1], fill=True)
        if i % 2 == 1:
            canv.setFillColor(white)
        else:
            canv.setFillColor(black)
        canv.drawCentredString(x, y, text) 
        canv.showPage()
    canv.save() 
开发者ID:nunb,项目名称:pdfnup,代码行数:22,代码来源:genpdf.py


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