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


Python Canvas.drawText方法代码示例

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


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

示例1: _get_output_page

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

示例2: writePDF

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def writePDF(drawings):
    "Create and save a PDF file containing some drawings."

    pdfPath = os.path.splitext(sys.argv[0])[0] + '.pdf'
    c = Canvas(pdfPath)
    c.setFont(_FONTS[0], 32)
    c.drawString(80, 750, 'ReportLab Graphics-Shapes Test')

    # Print drawings in a loop, with their doc strings.
    c.setFont(_FONTS[0], 12)
    y = 740
    i = 1
    for (drawing, docstring, funcname) in drawings:
        if y < 300:  # Allows 5-6 lines of text.
            c.showPage()
            y = 740
        # Draw a title.
        y = y - 30
        c.setFont(_FONTS[2],12)
        c.drawString(80, y, '%s (#%d)' % (funcname, i))
        c.setFont(_FONTS[0],12)
        y = y - 14
        textObj = c.beginText(80, y)
        textObj.textLines(docstring)
        c.drawText(textObj)
        y = textObj.getY()
        y = y - drawing.height
        drawing.drawOn(c, 80, y)
        i = i + 1

    c.save()
    print 'wrote %s ' % pdfPath
开发者ID:7o9,项目名称:stdm-plugin,代码行数:34,代码来源:testshapes.py

示例3: test

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def test(outDir='pdfout',shout=False):
    from reportlab.graphics.shapes import _baseGFontName, _baseGFontNameBI
    from reportlab.rl_config import verbose
    import os
    if not os.path.isdir(outDir):
        os.mkdir(outDir)
    fn = os.path.join(outDir,'renderPDF.pdf')
    c = Canvas(fn)
    c.setFont(_baseGFontName, 36)
    c.drawString(80, 750, 'Graphics Test')

    # print all drawings and their doc strings from the test
    # file

    #grab all drawings from the test module
    from reportlab.graphics import testshapes
    drawings = []
    for funcname in dir(testshapes):
        if funcname[0:10] == 'getDrawing':
            drawing = eval('testshapes.' + funcname + '()')  #execute it
            docstring = eval('testshapes.' + funcname + '.__doc__')
            drawings.append((drawing, docstring))

    #print in a loop, with their doc strings
    c.setFont(_baseGFontName, 12)
    y = 740
    i = 1
    for (drawing, docstring) in drawings:
        assert (docstring is not None), "Drawing %d has no docstring!" % i
        if y < 300:  #allows 5-6 lines of text
            c.showPage()
            y = 740
        # draw a title
        y = y - 30
        c.setFont(_baseGFontNameBI,12)
        c.drawString(80, y, 'Drawing %d' % i)
        c.setFont(_baseGFontName,12)
        y = y - 14
        textObj = c.beginText(80, y)
        textObj.textLines(docstring)
        c.drawText(textObj)
        y = textObj.getY()
        y = y - drawing.height
        draw(drawing, c, 80, y)
        i = i + 1
    if y!=740: c.showPage()

    c.save()
    if shout or verbose>2:
        print('saved %s' % ascii(fn))
开发者ID:AlonsoAyelen,项目名称:Voluntariado_veterinaria,代码行数:52,代码来源:renderPDF.py

示例4: sodelovanja

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def sodelovanja(request):
    sodelovanja = Sodelovanje.objects.all()
    person_form = PersonForm()
    if request.method == 'POST':
        form = SodelovanjeFilter(request.POST)
        if form.is_valid():
            for key, value in form.cleaned_data.items():
                ##'**' rabis zato da ti python resolva spremenljivke (as opposed da passa dobesedni string)
                if value and key != 'export':
                    sodelovanja = sodelovanja.filter(**{key: value})

    else:
        form = SodelovanjeFilter()

    try:
        export = form.cleaned_data['export']
        if export:
            from reportlab.pdfgen.canvas import Canvas
            output = StringIO()
            if export == 'txt':
                for i in sodelovanja:
                    output.write("%s\n" % i)
            elif export == 'pdf':
                pdf = Canvas(output)
                rhyme = pdf.beginText(30, 200)
                for i in sodelovanja:
                    rhyme.textLine(i.__unicode__())
                pdf.drawText(rhyme)
                pdf.showPage()
                pdf.save()
            elif export == 'csv':
                for i in sodelovanja:
                    output.write("%s\n" % i)

            response = HttpResponse(mimetype='application/octet-stream')
            response['Content-Disposition'] = "attachment; filename=" + 'export.' + export
            response.write(output.getvalue())
            return response

    except AttributeError:
        pass

    return render_to_response('org/sodelovanja.html',
        {'sodelovanja': sodelovanja, 'form': form,
        'admin_org': '%s/intranet/admin/org/' % settings.BASE_URL,
        'person_form': person_form},
        context_instance=RequestContext(request))
开发者ID:gandalfar,项目名称:Intranet,代码行数:49,代码来源:views.py

示例5: test

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def test():
    from reportlab.graphics.shapes import _baseGFontName, _baseGFontNameBI

    c = Canvas("renderPDF.pdf")
    c.setFont(_baseGFontName, 36)
    c.drawString(80, 750, "Graphics Test")

    # print all drawings and their doc strings from the test
    # file

    # grab all drawings from the test module
    from reportlab.graphics import testshapes

    drawings = []
    for funcname in dir(testshapes):
        if funcname[0:10] == "getDrawing":
            drawing = eval("testshapes." + funcname + "()")  # execute it
            docstring = eval("testshapes." + funcname + ".__doc__")
            drawings.append((drawing, docstring))

    # print in a loop, with their doc strings
    c.setFont(_baseGFontName, 12)
    y = 740
    i = 1
    for (drawing, docstring) in drawings:
        assert docstring is not None, "Drawing %d has no docstring!" % i
        if y < 300:  # allows 5-6 lines of text
            c.showPage()
            y = 740
        # draw a title
        y = y - 30
        c.setFont(_baseGFontNameBI, 12)
        c.drawString(80, y, "Drawing %d" % i)
        c.setFont(_baseGFontName, 12)
        y = y - 14
        textObj = c.beginText(80, y)
        textObj.textLines(docstring)
        c.drawText(textObj)
        y = textObj.getY()
        y = y - drawing.height
        draw(drawing, c, 80, y)
        i = i + 1
    if y != 740:
        c.showPage()

    c.save()
    print("saved renderPDF.pdf")
开发者ID:wolf29,项目名称:EG-notifications,代码行数:49,代码来源:renderPDF.py

示例6: test_single_page_text

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def test_single_page_text():
    filename = os.path.join(TEST_OUTPUT, "text.pdf")
    pdf = Canvas(filename, pagesize=(8 * 72, 6 * 72))
    text = pdf.beginText()
    text.setFont("Helvetica", 12)
    text.setTextOrigin(1 * 72, 3 * 72)
    text.textLine("Methink'st thou art a general offence and every" " man should beat thee.")
    pdf.drawText(text)
    pdf.showPage()
    pdf.save()

    pdfinfo = pageinfo.pdf_get_all_pageinfo(filename)

    assert len(pdfinfo) == 1
    page = pdfinfo[0]

    assert page["has_text"]
    assert len(page["images"]) == 0
开发者ID:clarionprogrammer,项目名称:OCRmyPDF,代码行数:20,代码来源:test_pageinfo.py

示例7: make_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def make_pdf(name, nome_musica, letra):
    '''
    str -> none

    Takes in a string text and creates a pdf file named file_name
    containing the file.

    >>> make_pdf("Hello world!")
    >>>
    >>>a = "Meu coracao nao sei porque, bate feliz quando te ve"
    >>>make_pdf(a)
    >>>

    '''
    
    pdf = Canvas(nome_musica+".pdf")
 
    pdf.setFillColorRGB(1, 0, 0)
    pdf.setStrokeColorRGB(1, 0, 0)
    
    ## An important thing to note here is that when specifying coordinates,the 
    ## origin  is in the lower left hand corner of the page, rather than the
    ## top left. The default unit of measurement is a point, equal to one
    ## seventy-second of an inch.
    pdf.setFont("Courier", 45)
    pdf.drawString(cm * 5, cm * 25, name)
    
    pdf.setFont("Courier", 30)
    text = pdf.beginText(cm * 5, cm * 20)
 
    for each in range(letra.count("\n")):
        text.textLine(letra.split("\n")[each])

    pdf.drawText(text)
    

    ## Close the page. The showPage method closes the current page.
    ## Any further drawing will occur on the next page

    pdf.showPage()

    ## The ReportLab Toolkit saves our page
    pdf.save()
开发者ID:Jbaumotte,项目名称:web2py,代码行数:45,代码来源:pdf.py

示例8: test_single_page_text

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def test_single_page_text(outdir):
    filename = outdir / 'text.pdf'
    pdf = Canvas(str(filename), pagesize=(8*72, 6*72))
    text = pdf.beginText()
    text.setFont('Helvetica', 12)
    text.setTextOrigin(1*72, 3*72)
    text.textLine("Methink'st thou art a general offence and every"
                  " man should beat thee.")
    pdf.drawText(text)
    pdf.showPage()
    pdf.save()

    info = pdfinfo.PdfInfo(filename)

    assert len(info) == 1
    page = info[0]

    assert page.has_text
    assert len(page.images) == 0
开发者ID:stweil,项目名称:OCRmyPDF,代码行数:21,代码来源:test_pageinfo.py

示例9: test

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def test():
    c = Canvas('renderPDF.pdf')
    c.setFont('Times-Roman', 36)
    c.drawString(80, 750, 'Graphics Test')

    # print all drawings and their doc strings from the test
    # file

    #grab all drawings from the test module
    from reportlab.graphics import testshapes
    drawings = []
    for funcname in dir(testshapes):
        if funcname[0:10] == 'getDrawing':
            drawing = eval('testshapes.' + funcname + '()')  #execute it
            docstring = eval('testshapes.' + funcname + '.__doc__')
            drawings.append((drawing, docstring))

    #print in a loop, with their doc strings
    c.setFont('Times-Roman', 12)
    y = 740
    i = 1
    for (drawing, docstring) in drawings:
        assert (docstring is not None), "Drawing %d has no docstring!" % i
        if y < 300:  #allows 5-6 lines of text
            c.showPage()
            y = 740
        # draw a title
        y = y - 30
        c.setFont('Times-BoldItalic',12)
        c.drawString(80, y, 'Drawing %d' % i)
        c.setFont('Times-Roman',12)
        y = y - 14
        textObj = c.beginText(80, y)
        textObj.textLines(docstring)
        c.drawText(textObj)
        y = textObj.getY()
        y = y - drawing.height
        draw(drawing, c, 80, y)
        i = i + 1
    if y!=740: c.showPage()

    c.save()
    print 'saved renderPDF.pdf'
开发者ID:makinacorpus,项目名称:reportlab-ecomobile,代码行数:45,代码来源:renderPDF.py

示例10: save_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
    def save_pdf(self, filename, margins=(1,1)):
        '''
        Make and save a PDF of this coverage plot, including a legend.

        Margins are expressed in inches: (top-bottom, left-right).
        '''
        from reportlab.lib.units import inch
        from reportlab.lib.pagesizes import letter
        from reportlab.pdfgen.canvas import Canvas

        c = Canvas(filename, pagesize=letter)

        # Compute margins.
        margin_top, margin_left = margins
        margin_top *= inch; margin_left *= inch
        whole_page_width, whole_page_height = letter
        page_top = whole_page_height - margin_top
        page_left = margin_left
        page_width = whole_page_width - 2*margin_left

        # Show the main image.
        image = self.img
        image_width = page_width
        image_height = image_width / image.size[0] * image.size[1]
        image_x = page_left
        image_y = page_top - image_height
        c.drawInlineImage(image, image_x, image_y, width=image_width, height=image_height)

        # Draw legends beneath the image.
        textobject = c.beginText()
        textobject.setTextOrigin(page_left, image_y - .5*inch)
        textobject.setFont('Helvetica', 14)
        for name, color in izip(self.names, self.colors):
            textobject.setFillColorRGB(*color)
            textobject.textLine(name)
        c.drawText(textobject)

        # Done.
        c.showPage()
        c.save()
开发者ID:Web5design,项目名称:divisi,代码行数:42,代码来源:blend.py

示例11: result2pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def result2pdf(result,reportfilename):
    '''Write HDR 2nd check output to a PDF report.
    Input: list of strings (report text).'''
    
    # Lines per page
    lpp = 48
    # Pages needed in report
    pages = ceil(len(result)/float(lpp))
    print '# of pages:',pages
    
    pdf = Canvas(reportfilename, pagesize = letter)
    report = pdf.beginText(inch * 1, inch * 10)
    
    # Single page report
    if len(result) < lpp:

        for line in result:
            report.textLine(line)
    
        pdf.drawText(report)
        pdf.showPage()

    # Or create a multi-page report
    else:
        page = 1
        l = 0
        while page < pages:
            # Reset page contents
            report = pdf.beginText(inch * 1, inch * 10)
        
            while l < lpp*page:
                print 'l:',l
                report.textLine(result[l])
                l += 1
            pdf.drawText(report)
            pdf.showPage()
            page += 1
        
        # Print last page
        # Reset page contents
        report = pdf.beginText(inch * 1, inch * 10)
        for line in result[int(pages-1)*lpp:]:
            report.textLine(line)
    
        pdf.drawText(report)
        pdf.showPage()
        
    pdf.save()
开发者ID:roycoding,项目名称:HDR-2nd-Check,代码行数:50,代码来源:result2pdf.py

示例12: to_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
 def to_pdf(self, imageFileName, outFileName, fontname="Times-Roman", fontsize=10, withVisibleOCRText=False, withVisibleImage=True, withVisibleBoundingBoxes=False):
   """
   Creates a PDF file with an image superimposed on top of the text.
   
   Text is positioned according to the bounding box of the lines in
   the hOCR file.
   
   The image need not be identical to the image used to create the hOCR file.
   It can be scaled, have a lower resolution, different color mode, etc.
   """
   if self.hocr is None:
     # warn that no text will be embedded in the output PDF
     print "Warning: No hOCR file specified. PDF will be image-only."
     
   im = Image.open(imageFileName)
   imwidthpx, imheightpx = im.size
   if 'dpi' in im.info:
     width = float(im.size[0])/im.info['dpi'][0]
     height = float(im.size[1])/im.info['dpi'][1]
   else:
     # we have to make a reasonable guess
     # set to None for now and try again using info from hOCR file
     width = height = None
     
     
   ocr_dpi = (300, 300) # a default, in case we can't find it
   
   # get dimensions of the OCR, which may not match the image
   if self.hocr is not None:
     for div in self.hocr.findall(".//%sdiv"%(self.xmlns)):
       if div.attrib['class'] == 'ocr_page':
         coords = self.element_coordinates(div)
         ocrwidth = coords[2]-coords[0]
         ocrheight = coords[3]-coords[1]
         if width is None:
           # no dpi info with the image
           # assume OCR was done at 300 dpi
           width = ocrwidth/300
           height = ocrheight/300
         ocr_dpi = (ocrwidth/width, ocrheight/height)
         break # there shouldn't be more than one, and if there is, we don't want it
           
   if width is None:
     # no dpi info with the image, and no help from the hOCR file either
     # this will probably end up looking awful, so issue a warning
     print "Warning: DPI unavailable for image %s. Assuming 96 DPI."%(imageFileName)
     width = float(im.size[0])/96
     height = float(im.size[1])/96
     
   # create the PDF file
   pdf = Canvas(outFileName, pagesize=(width*inch, height*inch), pageCompression=1) # page size in points (1/72 in.)
   
   # put the image on the page, scaled to fill the page
   if withVisibleImage:
     pdf.drawInlineImage(im, 0, 0, width=width*inch, height=height*inch)
   
   if self.hocr is not None:
     for word in self.hocr.findall(".//%sspan"%(self.xmlns)):
       if word.attrib['class'] == 'ocr_word':
         coords = self.element_coordinates(word)
         content = self._get_element_text(word)
         if content.rstrip() == '':
           continue
         text = pdf.beginText()
         text.setFont(fontname, fontsize)
         if not withVisibleOCRText:
           #text.setTextRenderMode(0) # visible
         #else:
           text.setTextRenderMode(3) # invisible
         
         # set cursor to bottom left corner of line bbox (adjust for dpi)
         # Can't determine original text's baseline, but guess that ypg
         # roughly push it down by ~2/3 of line height.  Correct for that.
         # PDF y coords increase going *up* the page, remember.  Assume "o" is
         # round so width == line height.
         origin_y = (height*inch)-(float(coords[3])/ocr_dpi[1])*inch
         if re.search(r"[gjpqy()]", content):
           origin_y += pdf.stringWidth("o") * 1/3
         if re.search(r"[\[\]()]", content):
           origin_y += pdf.stringWidth("o") * 1/3.5
         elif re.search(r"[,;]", content):
           origin_y += pdf.stringWidth("o") * 1/4
         text.setTextOrigin((float(coords[0])/ocr_dpi[0])*inch, origin_y)
         
         # scale the width of the text to fill the width of the line's bbox
         text.setHorizScale((((float(coords[2])/ocr_dpi[0]*inch)-(float(coords[0])/ocr_dpi[0]*inch))/pdf.stringWidth(content.rstrip(), fontname, fontsize))*100)
         
         # write the text to the page
         text.textLine(content.rstrip())
         pdf.drawText(text)
   
   # finish up the page and save it
   pdf.showPage()
   pdf.save()
开发者ID:zw,项目名称:HocrConverter,代码行数:96,代码来源:HocrConverter.py

示例13: draw_pdf

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]
def draw_pdf(buffer, member, details):
  from members.models import Member
  """ Draws the invoice """
  canvas = Canvas(buffer, pagesize=A4)
  canvas.translate(0, 29.7 * cm)
  canvas.setFont('Helvetica', 10)

  canvas.saveState()
  draw_header(canvas)
  canvas.restoreState()

  canvas.saveState()
  draw_footer(canvas)
  canvas.restoreState()

  canvas.saveState()
  draw_address(canvas)
  canvas.restoreState()

  # member address (aka head-of-list contact details)
  textobject = canvas.beginText(13 * cm, -3.5 * cm)
  textobject.textLine(member.head_of_list.first_name + ' ' + unicode.upper(member.head_of_list.last_name))
  if member.type == Member.ORG:
    textobject.textLine(member.organisation.name)
  textobject.textLine(member.address.street)
  textobject.textLine(member.address.postal_code + ' ' + member.address.town)
  textobject.textLine(get_country_from_address(member.address))
  canvas.drawText(textobject)

  # title
  canvas.setFont('Helvetica', 14)
  textobject = canvas.beginText(5.5 * cm, -6.75 * cm)
  textobject.textLine(u'Invoice for the CLUSIL membership for %s' % details['YEAR'])
  canvas.drawText(textobject)

  canvas.setFont('Helvetica', 10)

  # invoice summary
  textobject = canvas.beginText(1.5 * cm, -8 * cm)
  textobject.textLine(u'Invoice ID: %s' % details['ID'])
  textobject.textLine(u'Invoice Date: %s' % details['DATE'])
  canvas.drawText(textobject)

  # membership summary
  textobject = canvas.beginText(1.5 * cm, -9.5 * cm)
  textobject.textLine(u'Membership type: %s' % Member.MEMBER_TYPES[member.type][1])
  if member.type == Member.ORG:
    textobject.textLine(u'Head-of-list: %s' % details['FULLNAME'])
  else:
    textobject.textLine(u'Member: %s' % details['FULLNAME'])
  if member.type == Member.ORG:
    textobject.textLine(u'Nb of registered people: %i' % member.lvl)
  canvas.drawText(textobject)

  # list of people
  textobject = canvas.beginText(2.5 * cm, -11 * cm)
  #head-of-list:
  textobject.textLine(' - ' + member.head_of_list.first_name + ' ' + unicode.upper(member.head_of_list.last_name))
  if member.type == Member.ORG:
    #delegate:
    if member.delegate:
      textobject.textLine(' - ' + member.delegate.first_name + ' ' + unicode.upper(member.delegate.last_name))

    for u in member.users.all():
      textobject.textLine(' - ' + u.first_name + ' ' + unicode.upper(u.last_name))
  canvas.drawText(textobject)

  offset = member.users.count() / 3
  # fee 
  textobject = canvas.beginText(2.5 * cm, -(14+offset) * cm)
  textobject.textLine(u'Total amount of the CLUSIL membership fee: %s' % unicode(details['AMOUNT']) + u' EUR')
  canvas.drawText(textobject)

  # thank you message 
  textobject = canvas.beginText(1.5 * cm, -(16+offset) * cm)
  textobject.textLine(u'Thank you for being a CLUSIL member.')
  textobject.textLine(u'Please be so kind and pay the membership fee within the next two weeks.')
  canvas.drawText(textobject)

  canvas.showPage()
  canvas.save()
开发者ID:psteichen,项目名称:clusil-intranet,代码行数:83,代码来源:invoice.py

示例14: Address

# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import drawText [as 别名]

#.........这里部分代码省略.........
	#############################################################
	## Draw methods
	#############################################################

	def drawMain(self):
		# Horní lajna
		self.pdf.drawString(self.LEFT*mm, self.TOP*mm, self.title)
		self.pdf.drawString((self.LEFT+100)*mm, self.TOP*mm, "Variabilní symbol: %s" % self.vs)

		# Rámečky
		self.pdf.rect((self.LEFT)*mm, (self.TOP-68)*mm, (self.LEFT+156)*mm, 65*mm, stroke=True, fill=False)

		path = self.pdf.beginPath()
		path.moveTo((self.LEFT+88)*mm, (self.TOP-3)*mm)
		path.lineTo((self.LEFT+88)*mm, (self.TOP-68)*mm)
		self.pdf.drawPath(path, True, True)

		path = self.pdf.beginPath()
		path.moveTo((self.LEFT)*mm, (self.TOP-39)*mm)
		path.lineTo((self.LEFT+88)*mm, (self.TOP-39)*mm)
		self.pdf.drawPath(path, True, True)

		path = self.pdf.beginPath()
		path.moveTo((self.LEFT+88)*mm, (self.TOP-23)*mm)
		path.lineTo((self.LEFT+176)*mm, (self.TOP-23)*mm)
		self.pdf.drawPath(path, True, True)

	def drawClient(self,TOP,LEFT):
		self.pdf.setFont("DejaVu", 12)
		self.pdf.drawString((LEFT)*mm, (TOP)*mm, "Odběratel")
		self.pdf.setFont("DejaVu", 8)
		text = self.pdf.beginText((LEFT+2)*mm, (TOP-6)*mm)
		text.textLines("\n".join(self.client.getAddressLines()))
		self.pdf.drawText(text)
		text = self.pdf.beginText((LEFT+2)*mm, (TOP-28)*mm)
		text.textLines("\n".join(self.client.getContactLines()))
		self.pdf.drawText(text)

	def drawProvider(self,TOP,LEFT):
		self.pdf.setFont("DejaVu", 12)
		self.pdf.drawString((LEFT)*mm, (TOP)*mm, "Dodavatel")
		self.pdf.setFont("DejaVu", 8)
		text = self.pdf.beginText((LEFT+2)*mm, (TOP-6)*mm)
		text.textLines("\n".join(self.provider.getAddressLines()))
		self.pdf.drawText(text)
		text = self.pdf.beginText((LEFT+40)*mm, (TOP-6)*mm)
		text.textLines("\n".join(self.provider.getContactLines()))
		self.pdf.drawText(text)
		if self.provider.note:
			self.pdf.drawString((LEFT+2)*mm, (TOP-26)*mm, self.provider.note)

	def drawPayment(self,TOP,LEFT):
		self.pdf.setFont("DejaVu", 11)
		self.pdf.drawString((LEFT)*mm, (TOP)*mm, "Údaje pro platbu")
		#self.pdf.setFillColorRGB(255, 0, 0)
		text = self.pdf.beginText((LEFT+2)*mm, (TOP-6)*mm)
		text.textLines("""%s
Číslo účtu: %s
Variabilní symbol: %s"""%(self.provider.bank_name ,self.provider.bank_account, self.vs))
		self.pdf.drawText(text)

	def drawItems(self,TOP,LEFT):
		# Items
		path = self.pdf.beginPath()
		path.moveTo((LEFT)*mm, (TOP-4)*mm)
		path.lineTo((LEFT+176)*mm, (TOP-4)*mm)
开发者ID:MechanisM,项目名称:InvoiceGenerator,代码行数:70,代码来源:generator.py

示例15: test0

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


        enc = 'ETenms-B5-H'
        try:
            findCMapFile(enc)
        except:
            #they don't have the font pack, return silently
            return
        pdfmetrics.registerFont(CIDFont('MSung-Light',enc))

        c = Canvas(outputfile('test_multibyte_cht.pdf'))
        c.setFont('Helvetica', 24)
        c.drawString(100,700, 'Traditional Chinese Font Support')
        c.setFont('Helvetica', 10)
        c.drawString(100,680, 'Short sample: headline from Yahoo Hong Kong, 20 Oct 2001')

        c.setFont('MSung-Light-' + enc, 12)
        # this came from Yahoo Hong Kong leading story today
        message1 = '\xa5\xac\xae\xed\xbbP\xa6\xbf\xbfA\xa5\xc1\xa6b\xad\xba\xa6\xb8\xb7|\xad\xb1\xab\xe1\[email protected]\xa6P\xa8\xa3\xb0O\xaa\xcc\xa1A\xa5L\xbb\xa1\xa1A\xa8\xe2\xa4H\xaa\xba\xad\xba\xa6\xb8\xb7|\xad\xb1\xabD\xb1`'
        message2 = '\xa6n\xa1A\xa8\xc3\xaa\xed\xa5\xdc\[email protected]\xb5L\xba\xc3\xb0\xdd\xa4\xa4\xb0\xea\xa6b\xb3o\xad\xd3\xa5i\xa9\xc6\xaa\xba\xae\xc9\xa8\xe8\xa1A\xb7|\xbbP\xac\xfc\xb0\xea\xa4H\xa5\xc1\xaf\xb8\xa6b\[email protected]\xb0_\xa1C'
        message3 = '\xA7\x41\xA6\x6E\xB6\xDC'


        c.drawString(100, 655, message1)
        c.drawString(100, 639, message2)

        hBoxText(message3 + ' MSung-Light' , c, 100, 600, 'MSung-Light', enc)
        #hBoxText(message3 + ' MHei-Medium', c, 100, 580, 'MHei-Medium', enc)



        c.setFont('Helvetica', 10)
        tx = c.beginText(100, 500)
        tx.textLines("""
            This test document shows Traditional Chinese output from Reportlab PDF Library.
            You may use one Chinese font, MSung-Light, and a number of different
            encodings.

            The available encoding names (with comments from the PDF specification) are:
            encodings_cht = [
                'B5pc-H',           # Macintosh, Big Five character set, Big Five encoding,
                                    # Script Manager code 2
                'B5pc-V',           # Vertical version of B5pc-H
                'ETen-B5-H',        # Microsoft Code Page 950 (lfCharSet 0x88), Big Five
                                    # character set with ETen extensions
                'ETen-B5-V',        # Vertical version of ETen-B5-H
                'ETenms-B5-H',      # Microsoft Code Page 950 (lfCharSet 0x88), Big Five
                                    # character set with ETen extensions; this uses proportional
                                    # forms for half-width Latin characters.
                'ETenms-B5-V',      # Vertical version of ETenms-B5-H
                'CNS-EUC-H',        # CNS 11643-1992 character set, EUC-TW encoding
                'CNS-EUC-V',        # Vertical version of CNS-EUC-H
                'UniCNS-UCS2-H',    # Unicode (UCS-2) encoding for the Adobe-CNS1
                                    # character collection
                'UniCNS-UCS2-V'    # Vertical version of UniCNS-UCS2-H.
                ]

            The next 32 pages show the complete character set available in the encoding
            "ETen-B5-H".  This is Big5 with the ETen extensions.  ETen extensions are the
            most common extension to Big5 and include circled and roman numbers, Japanese
            hiragana and katakana, Cyrillic and fractions in rows C6-C8; and 7 extra characters
            and some line drawing characters in row F9.
            """)
        c.drawText(tx)
        c.setFont('Helvetica',10)
        c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())

        c.showPage()

        # full Big5 code page
        c.setFont('Helvetica', 18)
        c.drawString(72,750, 'Characters available in Big 5')
        y = 500
        for row in range(0xA1,0xFF):
            cc = Big5CodeChart(row, 'MSung-Light',enc)
            cc.charsPerRow = 16
            cc.rows = 10
            cc.codePoints = 160
            cc.drawOn(c, 72, y)
            y = y - cc.height - 25
            if y < 50:
                c.setFont('Helvetica',10)
                c.drawCentredString(297, 36, 'Page %d' % c.getPageNumber())
                c.showPage()
                y = 600


        c.save()
        if VERBOSE:
            print 'saved '+outputfile('test_multibyte_cht.pdf')
开发者ID:eaudeweb,项目名称:naaya,代码行数:97,代码来源:test_multibyte_cht.py


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