本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.beginText方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.beginText方法的具体用法?Python Canvas.beginText怎么用?Python Canvas.beginText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.pdfgen.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.beginText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: result2pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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()
示例2: _get_output_page
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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)
示例3: writePDF
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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
示例4: test
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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))
示例5: sodelovanja
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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))
示例6: test
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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")
示例7: test_single_page_text
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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
示例8: make_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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()
示例9: test
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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'
示例10: test_single_page_text
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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
示例11: save_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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()
示例12: to_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [as 别名]
def to_pdf(self, outFileName, imageFileName=None, showBoundingboxes=False,
fontname="Helvetica", invisibleText=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 have a lower resolution, different color mode, etc.
"""
# create the PDF file
# page size in points (1/72 in.)
pdf = Canvas(
outFileName, pagesize=(self.width, self.height), pageCompression=1)
# draw bounding box for each paragraph
# light blue for bounding box of paragraph
pdf.setStrokeColorRGB(0, 1, 1)
# light blue for bounding box of paragraph
pdf.setFillColorRGB(0, 1, 1)
pdf.setLineWidth(0) # no line for bounding box
for elem in self.hocr.findall(
".//%sp[@class='%s']" % (self.xmlns, "ocr_par")):
elemtxt = self._get_element_text(elem).rstrip()
if len(elemtxt) == 0:
continue
pxl_coords = self.element_coordinates(elem)
pt = self.pt_from_pixel(pxl_coords)
# draw the bbox border
if showBoundingboxes:
pdf.rect(
pt.x1, self.height - pt.y2, pt.x2 - pt.x1, pt.y2 - pt.y1,
fill=1)
# check if element with class 'ocrx_word' are available
# otherwise use 'ocr_line' as fallback
elemclass = "ocr_line"
if self.hocr.find(
".//%sspan[@class='ocrx_word']" % (self.xmlns)) is not None:
elemclass = "ocrx_word"
# itterate all text elements
# light green for bounding box of word/line
pdf.setStrokeColorRGB(1, 0, 0)
pdf.setLineWidth(0.5) # bounding box line width
pdf.setDash(6, 3) # bounding box is dashed
pdf.setFillColorRGB(0, 0, 0) # text in black
for elem in self.hocr.findall(
".//%sspan[@class='%s']" % (self.xmlns, elemclass)):
elemtxt = self._get_element_text(elem).rstrip()
elemtxt = self.replace_unsupported_chars(elemtxt)
if len(elemtxt) == 0:
continue
pxl_coords = self.element_coordinates(elem)
pt = self.pt_from_pixel(pxl_coords)
# draw the bbox border
if showBoundingboxes:
pdf.rect(
pt.x1, self.height - pt.y2, pt.x2 - pt.x1, pt.y2 - pt.y1,
fill=0)
text = pdf.beginText()
fontsize = pt.y2 - pt.y1
text.setFont(fontname, fontsize)
if invisibleText:
text.setTextRenderMode(3) # Invisible (indicates OCR text)
# set cursor to bottom left corner of bbox (adjust for dpi)
text.setTextOrigin(pt.x1, self.height - pt.y2)
# scale the width of the text to fill the width of the bbox
text.setHorizScale(
100 * (pt.x2 - pt.x1) / pdf.stringWidth(
elemtxt, fontname, fontsize))
# write the text to the page
text.textLine(elemtxt)
pdf.drawText(text)
# put the image on the page, scaled to fill the page
if imageFileName is not None:
pdf.drawImage(imageFileName, 0, 0,
width=self.width, height=self.height)
# finish up the page and save it
pdf.showPage()
pdf.save()
示例13: to_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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()
示例14: draw_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [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()
示例15: Address
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginText [as 别名]
#.........这里部分代码省略.........
return data
#############################################################
## 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()