本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.saveState方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.saveState方法的具体用法?Python Canvas.saveState怎么用?Python Canvas.saveState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.pdfgen.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.saveState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test3
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
def test3(self):
from reportlab.pdfgen.canvas import Canvas
aW=307
styleSheet = getSampleStyleSheet()
bt = styleSheet['BodyText']
btj = ParagraphStyle('bodyText1j',parent=bt,alignment=TA_JUSTIFY)
p=Paragraph("""<a name='top'/>Subsequent pages test pageBreakBefore, frameBreakBefore and
keepTogether attributes. Generated at 1111. The number in brackets
at the end of each paragraph is its position in the story. llllllllllllllllllllllllll
bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc ddddddddddddddddddddd eeeeyyy""",btj)
w,h=p.wrap(aW,1000)
canv=Canvas('test_platypus_paragraph_just.pdf',pagesize=(aW,h))
i=len(canv._code)
p.drawOn(canv,0,0)
ParaCode=canv._code[i:]
canv.saveState()
canv.setLineWidth(0)
canv.setStrokeColorRGB(1,0,0)
canv.rect(0,0,aW,h)
canv.restoreState()
canv.showPage()
canv.save()
from reportlab import rl_config
x = rl_config.paraFontSizeHeightOffset and '50' or '53.17'
good = ['q', '1 0 0 1 0 0 cm', 'q', 'BT 1 0 0 1 0 '+x+' Tm 3.59 Tw 12 TL /F1 10 Tf 0 0 0 rg (Subsequent pages test pageBreakBefore, frameBreakBefore and) Tj T* 0 Tw .23 Tw (keepTogether attributes. Generated at 1111. The number in brackets) Tj T* 0 Tw .299167 Tw (at the end of each paragraph is its position in the story. llllllllllllllllllllllllll) Tj T* 0 Tw 66.9 Tw (bbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccc) Tj T* 0 Tw (ddddddddddddddddddddd eeeeyyy) Tj T* ET', 'Q', 'Q']
ok= ParaCode==good
assert ok, "\nParaCode=%r\nexpected=%r" % (ParaCode,good)
示例2: test_06_fontsize
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [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()
示例3: make_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [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()
示例4: _get_output_page
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [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)
示例5: piece_stickers
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [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 ()
示例6: _on_other_page
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [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()
示例7: mailing_labels
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [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 ()
示例8: Sla2Pdf_classic
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
#.........这里部分代码省略.........
else:
fontName = 'Courier'
elif 'HELVETICA' in fontStr:
if boldStr in fontStr and obliqueStr in fontStr:
fontName = 'Helvetica-BoldOblique'
elif boldStr in fontStr:
fontName = 'Helvetica-Bold'
elif obliqueStr in fontStr:
fontName = 'Helvetica-Oblique'
else:
fontName = 'Helvetica'
else:
if boldStr in fontStr and (obliqueStr in fontStr or italicStr in fontStr):
fontName = 'Times-BoldItalic'
elif boldStr in fontStr:
fontName = 'Times-Bold'
elif obliqueStr in fontStr or italicStr in fontStr:
fontName = 'Times-Italic'
else:
fontName = 'Times-Roman'
return fontName
def drawImage(width, height):
""" Drawing an image """
(imgPath, imgFile) = os.path.split(self.pfile)
img = utils.ImageReader(Environment.imagesDir + imgFile)
self.canvas.drawImage(img,
xPos - self.pageProperties[self.pdfPage][9],
self.pageProperties[0][7] - yPos - height + self.pageProperties[self.pdfPage][10],
width=width,
height=height)
self.canvas.saveState()
def drawCell():
""" Drawing a cell text """
# Finding background
cellBackground = self.pageObject.get('PCOLOR')
if cellBackground in self.colorList:
try:
hexCellColor = self.colorList[cellBackground]
background = colors.HexColor(str(hexCellColor))
except:
background = colors.HexColor('#ffffff')
else:
background = colors.HexColor('#ffffff')
stile = TableStyle([('ROWBACKGROUNDS', (0,0), (0,0), (background, background))])
# Borders
bottomLine = int(self.pageObject.get('BottomLine'))
topLine = int(self.pageObject.get('TopLine'))
leftLine = int(self.pageObject.get('LeftLine'))
rightLine = int(self.pageObject.get('RightLine'))
lineWidth = float(self.pageObject.get('PWIDTH'))
borderColor = self.pageObject.get('PCOLOR2')
alignment = " "
# Finding value and cell's style
if self.version:
paras = self.pageObject.findall('para')
itexts = self.pageObject.findall('ITEXT')
ch = ''
matrix = []
if len(itexts)>=1:
if len(itexts)>1:
示例9: draw_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
def draw_pdf(buffer, invoice):
""" Draws the invoice """
canvas = Canvas(buffer, pagesize=A4)
canvas.translate(0, 29.7 * cm)
canvas.setFont('Helvetica', 10)
canvas.saveState()
header_func(canvas)
canvas.restoreState()
canvas.saveState()
footer_func(canvas)
canvas.restoreState()
canvas.saveState()
address_func(canvas)
canvas.restoreState()
# Client address
textobject = canvas.beginText(1.5 * cm, -2.5 * cm)
if invoice.address.contact_name:
textobject.textLine(invoice.address.contact_name)
textobject.textLine(invoice.address.address_one)
if invoice.address.address_two:
textobject.textLine(invoice.address.address_two)
textobject.textLine(invoice.address.town)
if invoice.address.county:
textobject.textLine(invoice.address.county)
textobject.textLine(invoice.address.postcode)
textobject.textLine(invoice.address.country.name)
canvas.drawText(textobject)
# Info
textobject = canvas.beginText(1.5 * cm, -6.75 * cm)
textobject.textLine(u'Invoice ID: %s' % invoice.invoice_id)
textobject.textLine(u'Invoice Date: %s' % invoice.invoice_date.strftime('%d %b %Y'))
textobject.textLine(u'Client: %s' % invoice.user.username)
canvas.drawText(textobject)
# Items
data = [[u'Quantity', u'Description', u'Amount', u'Total'], ]
for item in invoice.items.all():
data.append([
item.quantity,
item.description,
format_currency(item.unit_price, invoice.currency),
format_currency(item.total(), invoice.currency)
])
data.append([u'', u'', u'Total:', format_currency(invoice.total(), invoice.currency)])
table = Table(data, colWidths=[2 * cm, 11 * cm, 3 * cm, 3 * cm])
table.setStyle([
('FONT', (0, 0), (-1, -1), 'Helvetica'),
('FONTSIZE', (0, 0), (-1, -1), 10),
('TEXTCOLOR', (0, 0), (-1, -1), (0.2, 0.2, 0.2)),
('GRID', (0, 0), (-1, -2), 1, (0.7, 0.7, 0.7)),
('GRID', (-2, -1), (-1, -1), 1, (0.7, 0.7, 0.7)),
('ALIGN', (-2, 0), (-1, -1), 'RIGHT'),
('BACKGROUND', (0, 0), (-1, 0), (0.8, 0.8, 0.8)),
])
tw, th, = table.wrapOn(canvas, 15 * cm, 19 * cm)
table.drawOn(canvas, 1 * cm, -8 * cm - th)
canvas.showPage()
canvas.save()
示例10: _on_first_page
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
def _on_first_page(self, canvas: Canvas, doc):
canvas.setCreator('pretix.eu')
canvas.setTitle(pgettext('invoice', 'Invoice {num}').format(num=self.invoice.number))
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())
textobject = canvas.beginText(25 * mm, (297 - 15) * mm)
textobject.setFont('OpenSansBd', 8)
textobject.textLine(pgettext('invoice', 'Invoice from').upper())
canvas.drawText(textobject)
self._draw_invoice_from(canvas)
textobject = canvas.beginText(25 * mm, (297 - 50) * mm)
textobject.setFont('OpenSansBd', 8)
textobject.textLine(pgettext('invoice', 'Invoice to').upper())
canvas.drawText(textobject)
self._draw_invoice_to(canvas)
textobject = canvas.beginText(125 * mm, (297 - 38) * mm)
textobject.setFont('OpenSansBd', 8)
textobject.textLine(pgettext('invoice', 'Order code').upper())
textobject.moveCursor(0, 5)
textobject.setFont('OpenSans', 10)
textobject.textLine(self.invoice.order.full_code)
canvas.drawText(textobject)
textobject = canvas.beginText(125 * mm, (297 - 50) * mm)
textobject.setFont('OpenSansBd', 8)
if self.invoice.is_cancellation:
textobject.textLine(pgettext('invoice', 'Cancellation number').upper())
textobject.moveCursor(0, 5)
textobject.setFont('OpenSans', 10)
textobject.textLine(self.invoice.number)
textobject.moveCursor(0, 5)
textobject.setFont('OpenSansBd', 8)
textobject.textLine(pgettext('invoice', 'Original invoice').upper())
textobject.moveCursor(0, 5)
textobject.setFont('OpenSans', 10)
textobject.textLine(self.invoice.refers.number)
else:
textobject.textLine(pgettext('invoice', 'Invoice number').upper())
textobject.moveCursor(0, 5)
textobject.setFont('OpenSans', 10)
textobject.textLine(self.invoice.number)
textobject.moveCursor(0, 5)
if self.invoice.is_cancellation:
textobject.setFont('OpenSansBd', 8)
textobject.textLine(pgettext('invoice', 'Cancellation date').upper())
textobject.moveCursor(0, 5)
textobject.setFont('OpenSans', 10)
textobject.textLine(date_format(self.invoice.date, "DATE_FORMAT"))
textobject.moveCursor(0, 5)
textobject.setFont('OpenSansBd', 8)
textobject.textLine(pgettext('invoice', 'Original invoice date').upper())
textobject.moveCursor(0, 5)
textobject.setFont('OpenSans', 10)
textobject.textLine(date_format(self.invoice.refers.date, "DATE_FORMAT"))
textobject.moveCursor(0, 5)
else:
textobject.setFont('OpenSansBd', 8)
textobject.textLine(pgettext('invoice', 'Invoice date').upper())
textobject.moveCursor(0, 5)
textobject.setFont('OpenSans', 10)
textobject.textLine(date_format(self.invoice.date, "DATE_FORMAT"))
textobject.moveCursor(0, 5)
canvas.drawText(textobject)
if self.invoice.event.settings.invoice_logo_image:
logo_file = self.invoice.event.settings.get('invoice_logo_image', binary_file=True)
ir = ThumbnailingImageReader(logo_file)
try:
ir.resize(25 * mm, 25 * mm, 300)
except:
logger.exception("Can not resize image")
pass
canvas.drawImage(ir,
95 * mm, (297 - 38) * mm,
width=25 * mm, height=25 * mm,
preserveAspectRatio=True, anchor='n',
mask='auto')
def shorten(txt):
txt = str(txt)
p = Paragraph(txt.strip().replace('\n', '<br />\n'), style=self.stylesheet['Normal'])
p_size = p.wrap(65 * mm, 50 * mm)
while p_size[1] > 2 * self.stylesheet['Normal'].leading:
txt = ' '.join(txt.replace('…', '').split()[:-1]) + '…'
p = Paragraph(txt.strip().replace('\n', '<br />\n'), style=self.stylesheet['Normal'])
p_size = p.wrap(65 * mm, 50 * mm)
return txt
#.........这里部分代码省略.........
示例11: Report
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
#.........这里部分代码省略.........
## Create the page number label; 'Page X of'
self.page_num = Field()
self.page_num.style.horizontal_alignment = alignment.RIGHT
self.page_num.style.vertical_alignment = alignment.TOP
self.page_num.width = self._working_width - 13
#self.page_num.style.color = (.6,.6,.6)
self.page_num.horizontal_padding = 0
self.page_num.style.size = 8
## Create the last page number label
self.last_page = Field()
#self.last_page.style.horizontal_alignment = alignment.LEFT
self.last_page.style.vertical_alignment = alignment.TOP
#self.last_page.width = self._working_width
#self.last_page.style.color = (.6,.6,.6)
self.last_page.horizontal_padding = 0
self.last_page.style.size = 8
## Objects to be drawn
self.draw_list = []
self._page_count = 1
#-----------------------------------------------------------------------Add
def add(self, item):
## Add any object that, duck-typingly, has a 'draw_some' method
self.draw_list.append(item)
#--------------------------------------------------------------------Create
def create(self):
self.canvas.setAuthor(self.author)
self.canvas.setTitle(self.title)
self.canvas.setSubject('Python Generated Report')
self._draw_header()
self._draw_footer()
vspace = self._working_height
left = self.left_margin
right = self.page_width - self.right_margin
for item in self.draw_list:
while True:
if vspace < 1:
self._start_new_page()
vspace = self._working_height
yoff = self.bottom_margin + vspace
used = item.draw_some(self.canvas, left, right, yoff, vspace)
if used == 0:
break
else:
vspace -= used
## Add the numbering for last page
## We have to do this as a PDF 'Form' object since we don't know in
## advance how many pages there will be.
self.canvas.beginForm('last_page')
self.canvas.saveState()
self.last_page.value = '%d' % self._page_count
self.last_page.draw(self.canvas,
self._right_edge - ( self.right_margin + 14),
self.bottom_margin * .65)
self.canvas.restoreState()
self.canvas.endForm()
## Close the PDF
self.canvas.save()
#----------------------------------------------------------------Start Page
def _start_new_page(self):
self._page_count += 1
self.canvas.showPage()
self._draw_header()
self._draw_footer()
#---------------------------------------------------------------Draw Header
def _draw_header(self):
self.header.value = self.title
self.header.draw(self.canvas, self.left_margin, self._top_edge -
(self.top_margin * .65) )
#---------------------------------------------------------------Draw Footer
def _draw_footer(self):
self.footer.value = self.author
self.footer.draw(self.canvas, self.left_margin,
self.bottom_margin * .65)
self.date.draw(self.canvas, self.left_margin,
self.bottom_margin * .65)
self.page_num.value = 'Page %d of ' % self._page_count
self.page_num.draw(self.canvas, self.left_margin,
self.bottom_margin * .65)
self.canvas.doForm('last_page')
示例12: Sla2Pdf_ng
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
class Sla2Pdf_ng(object):
""" sla to pdf format translation """
def __init__(self, document, pdfFolder,
version, tablesProperties,
pgObjList, numPages,
iteratableGroups):
"""
Build a template object based on the specified file-like
object and sequence of objects
"""
self.pdfFolder = pdfFolder
self.pdfFileName = '_temp'
self.version = version
self.tablesProperties = tablesProperties
self.document = document
self.pageObjects = self.document.findall('PAGEOBJECT')
self.pgObjList = pgObjList
self.numPages = numPages
self.iteratableGroups = iteratableGroups
self.translate()
def translate(self):
self.pageProperties = Sla2pdfUtils.pageProFunc(self.document)
self.canvas = Canvas(filename = self.pdfFolder + self.pdfFileName + '.pdf', pagesize=(self.pageProperties[0][8],self.pageProperties[0][7]))
# Page's table
reiter = False
self.pdfPage = 0
for e in xrange(0, self.numPages):
self.pdfPage = e
for group in self.tablesProperties:
self.group = group.keys()[0]
self.tablesPropertie = group.values()[0]
try:
self.group= self.group.strip().split('%%%')[0]
except:
self.group= self.group.strip()
if self.group in self.iteratableGroups:
colu = int(self.tablesPropertie['columns'])
self.tablesPropertie['iterproper'] = self.tablesPropertie['parasobj'][colu:(colu*2)]
reiter = True
cells = int(self.tablesPropertie['cells'])
# Closing pages (elements of the same page must be near)
if "noGroup" in self.group and self.tablesPropertie["pfile"] != "" :
#print "IMMAGINEEEEEEEEEEEEEEE", self.group, self.tablesPropertie["isTableItem"]
self.drawImage(group=self.group) # IMMAGINE
elif "noGroup" in self.group and self.tablesPropertie["pfile"] == "":
#print "MONOCELLAAAAAAA", self.group, self.tablesPropertie
self.drawTable(group =self.group, monocell=True)# MONOCELLA
else:
# print "TABELLAAAAAAAA", self.group, self.tablesPropertie["isTableItem"]
self.drawTable(group =self.group, reiter = reiter) # TABELLA
self.canvas.saveState()
self.canvas.showPage()
self.canvas.save()
def drawImage(self,group):
""" Drawing an image """
pfile = self.tablesPropertie['pfile']
(imgPath, imgFile) = os.path.split(pfile)
#innerIterator = self.iterator
width = self.tablesPropertie['widths'][0]
height = self.tablesPropertie['heights'][0]
xPos = self.tablesPropertie['xpos'][0]
yPos = self.tablesPropertie['ypos'][0]
img = utils.ImageReader(Environment.imagesDir + imgFile)
self.canvas.drawImage(img,
xPos - self.pageProperties[self.pdfPage][9],
self.pageProperties[0][7] - yPos - height + self.pageProperties[self.pdfPage][10],
width=width,
height=height)
self.canvas.saveState()
def drawTable(self, group=None, monocell=None, reiter = None):
""" Drawing a table """
matrix = []
lst = []
matrix2 = []
vector = []
# Total of element's table
cells = int(self.tablesPropertie['cells'])
columns = int(self.tablesPropertie['columns'])
rows = int(self.tablesPropertie['rows'])
widths = self.tablesPropertie['widths']
heights = self.tablesPropertie['heights']
xpos = self.tablesPropertie['xpos']
ypos = self.tablesPropertie['ypos']
# print "DATI", cells, columns, rows, group, heights, widths
contColumns = 0
ch = ''
col = 0
cycle = False
vector = []
alignment= None
itexts = self.tablesPropertie['itextsobj']
paras = self.tablesPropertie['parasobj']
stile = TableStyle([])
stile.add('VALIGN',(0,0),(-1,-1),'TOP')
tblprop = self.tablesPropertie['cellProperties']
if monocell==True:
#.........这里部分代码省略.........
示例13: draw_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
def draw_pdf(buffer, member, details):
from members.models import Member
""" Draws the credit """
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'CREDIT NOTE')
canvas.drawText(textobject)
canvas.setFont('Helvetica', 10)
# credit summary
textobject = canvas.beginText(1.5 * cm, -8 * cm)
textobject.textLine(u'ID: %s' % details['ID'])
textobject.textLine(u'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'])
canvas.drawText(textobject)
# fee
textobject = canvas.beginText(2.5 * cm, -12 * cm)
textobject.textLine(u'Amount of the credit note: %s' % unicode(details['AMOUNT']) + u' EUR')
canvas.drawText(textobject)
# thank you message
textobject = canvas.beginText(1.5 * cm, -14 * cm)
textobject.textLine(u'Thank you for being a CLUSIL member.')
canvas.drawText(textobject)
canvas.showPage()
canvas.save()
示例14: draw_pdf
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [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: main
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import saveState [as 别名]
def main():
pdfmetrics.registerFont(TTFont('Dosis', 'Dosis-Medium.ttf'))
stars = []
with open('bsc5.dat', 'rb') as f:
for line in f:
line = '.' + line # switch to 1-based indexing
if not line[62].strip():
continue # skip coordinate-less novas
letter = intern(line[8:11])
if letter == ' ':
letter = None
h, m, s = float(line[61:63]), float(line[63:65]), float(line[65:69])
ra = (h + (m + s / 60.0) / 60.0) * tau / 24.0
d, m, s = float(line[69:72]), float(line[72:74]), float(line[76:78])
dec = (d + (m + s / 60.0) / 60.0) * tau / 360.0
mag = float(line[103:108])
stars.append((letter, ra, dec, mag))
h, w = 48, 96
c = Canvas('logo.pdf', pagesize=(w, h))
c.setFillColor('white')
c.rect(0, 0, w, h, stroke=0, fill=1)
c.setFillColor(bright_star_color)
rotation = 10.0 * tau / 360.0
# magscale = 0.1
# For 10 degrees:
x_offset = 96 -33.5
y_offset = h +37.5
# For 15 degrees:
# x_offset = 96 -28.5
# y_offset = 96 +0.5
# for 45 degrees:
# x_offset = 96 -13.5
# y_offset = 96 -10
small_glyphs = []
c.setFont('Helvetica', 2)
for letter, ra, dec, mag in stars:
# if mag > 4.0:
# continue
d = - (dec - quarter_tau) * 100
ra += rotation
x = d * sin(ra)
y = d * cos(ra)
if y < -63.0 or y > -39.0:
continue
if x < -43.0 or x > 19.0:
continue
x += x_offset
y += y_offset
r = ((13.0 - mag) / 10.0) ** 4.0 #* magscale
r = min(r, 1.0)
if r < 0.5:
small_glyphs.append((x, y, r))
else:
if letter is not None:
c.saveState()
greek_letter, offset = greeks[letter]
c.setFillColor(greek_color)
c.drawString(x+offset, y+0.5, greek_letter)
if letter == 'Alp':
c.setFillColor(alpha_star_color)
c.circle(x, y, r, stroke=0, fill=1)
c.restoreState()
if letter != 'Alp':
c.circle(x, y, r, stroke=0, fill=1)
else:
c.circle(x, y, r, stroke=0, fill=1)
c.setFillColor(dim_star_color)
for x, y, r in small_glyphs:
c.circle(x, y, r, stroke=0, fill=1)
c.setFillColor(text_color) #, alpha=0.5)
c.setFont('Dosis', 24)
sw = c.stringWidth('Skyfield')
c.drawString(w // 2 - sw // 2, h - 40, 'Skyfield')
c.showPage()
with open('logo.pdf', 'wb') as f:
f.write(c.getpdfdata())