本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas.beginPath方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.beginPath方法的具体用法?Python Canvas.beginPath怎么用?Python Canvas.beginPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.pdfgen.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.beginPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_label
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [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')
示例2: _create_new_canvas
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
def _create_new_canvas(self):
pagesize = PAGE_SIZE_MAP[self.pagesize]
units = UNITS_MAP[self.dest_box_units]
gc = Canvas(filename=self.filename, pagesize=pagesize)
width = pagesize[0] * units * inch / 72.0
height = pagesize[1] * units * inch / 72.0
x = self.dest_box[0] * units
y = self.dest_box[1] * units
w = self.dest_box[2] * units
h = self.dest_box[3] * units
if w < 0:
w += width
if h < 0:
h += height
if w < 0 or h < 0:
warnings.warn("Margins exceed page dimensions.")
self.gc = None
return
gc.translate(x,y)
path = gc.beginPath()
path.rect(0, 0, w, h)
gc.clipPath(path, stroke=0, fill=0)
return gc
示例3: draw_label_bounds
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
def draw_label_bounds(self, c: Canvas, x, y):
p = c.beginPath()
x -= 0.5*self.label_width
y -= 0.5*self.label_height
p.moveTo(x, y)
p.lineTo(x, y + self.label_height)
p.lineTo(x + self.label_width, y + self.label_height)
p.lineTo(x + self.label_width, y)
p.lineTo(x, y)
p.close()
c.drawPath(p)
示例4: __init__
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
def __init__(self,
IDmodele=None,
taillePage=(210, 297),
listeValeurs=[],
margeHaut=10,
margeGauche=10,
margeBas = 10,
margeDroite=10,
espaceVertical=5,
espaceHorizontal=5,
nbre_copies=1,
AfficherContourEtiquette=True,
AfficherReperesDecoupe=True,
):
# ----------------------------------------------------------------------------------------------------------------------------------------
def AfficheReperesDecoupe():
if AfficherReperesDecoupe == True :
canvas.setStrokeColor( (0.9, 0.9, 0.9) )
canvas.setLineWidth(0.25)
# Repères de colonnes
for y1, y2 in [(hauteurPage*mm-4*mm, hauteurPage*mm-margeHaut*mm+2*mm), (4*mm, margeBas-2*mm)] :
x = margeGauche*mm
for numColonne in range(0, nbreColonnes):
canvas.line(x, y1, x, y2)
x += largeurEtiquette*mm
canvas.line(x, y1, x, y2)
x += espaceHorizontal*mm
# Repères de lignes
for x1, x2 in [(4*mm, margeGauche*mm-2*mm), (largeurPage*mm-4*mm, largeurPage*mm-margeDroite*mm+2*mm)] :
y = hauteurPage*mm - margeHaut*mm
for numLigne in range(0, nbreLignes):
canvas.line(x1, y, x2, y)
y -= hauteurEtiquette*mm
canvas.line(x1, y, x2, y)
y -= espaceVertical*mm
# -----------------------------------------------------------------------------------------------------------------------------------------
largeurPage = taillePage[0]
hauteurPage = taillePage[1]
# Initialisation du modèle de document
modeleDoc = DLG_Noedoc.ModeleDoc(IDmodele=IDmodele)
largeurEtiquette = modeleDoc.dictInfosModele["largeur"]
hauteurEtiquette = modeleDoc.dictInfosModele["hauteur"]
# Calcul du nbre de colonnes et de lignes
nbreColonnes = (largeurPage - margeGauche - margeDroite + espaceHorizontal) / (largeurEtiquette + espaceHorizontal)
nbreLignes = (hauteurPage - margeHaut - margeBas + espaceVertical) / (hauteurEtiquette + espaceVertical)
# Initialisation du PDF
nomDoc = FonctionsPerso.GenerationNomDoc("ETIQUETTES", "pdf")
canvas = Canvas(nomDoc, pagesize=(largeurPage*mm, hauteurPage*mm))
# Création des étiquettes
numColonne = 0
numLigne = 0
for dictValeurs in listeValeurs :
for num_copie in range(0, nbre_copies) :
x = margeGauche + ((largeurEtiquette + espaceHorizontal) * numColonne)
y = hauteurPage - margeHaut - hauteurEtiquette - ((hauteurEtiquette + espaceVertical) * numLigne)
# Positionnement sur la feuille
canvas.saveState()
canvas.translate(x*mm, y*mm)
# Création du clipping
p = canvas.beginPath()
canvas.setStrokeColor( (1, 1, 1) )
canvas.setLineWidth(0.25)
p.rect(0, 0, largeurEtiquette*mm, hauteurEtiquette*mm)
canvas.clipPath(p)
# Dessin de l'étiquette
modeleDoc.DessineFond(canvas, dictChamps=dictValeurs)
etat = modeleDoc.DessineTousObjets(canvas, dictChamps=dictValeurs)
if etat == False :
return
# Dessin du contour de l'étiquette
if AfficherContourEtiquette == True :
canvas.setStrokeColor( (0, 0, 0) )
canvas.setLineWidth(0.25)
canvas.rect(0, 0, largeurEtiquette*mm, hauteurEtiquette*mm)
canvas.restoreState()
# Saut de colonne
numColonne += 1
# Saut de ligne
if numColonne > nbreColonnes - 1 :
numLigne += 1
numColonne = 0
# Saut de page
if numLigne > nbreLignes - 1 :
AfficheReperesDecoupe()
canvas.showPage()
numLigne = 0
#.........这里部分代码省略.........
示例5: Address
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
class Invoice:
client = Address()
provider = Address()
items = []
title = "Faktura"
vs = "00000000"
creator = ""
sign_image = None
payment_days = 14
paytype = "Převodem"
pdffile = None
def __init__(self):
self.TOP = 260
self.LEFT = 20
pdfmetrics.registerFont(TTFont('DejaVu', '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf'))
self.pdffile = NamedTemporaryFile(delete=False)
self.pdf = Canvas(self.pdffile.name, pagesize = letter)
self.pdf.setFont("DejaVu", 15)
self.pdf.setStrokeColorRGB(0, 0, 0)
def __del__(self):
if os.path.isfile(self.pdffile.name):
os.unlink(self.pdffile.name)
#############################################################
## Setters
#############################################################
def setClient(self, address):
self.client = address
def setProvider(self, address):
self.provider = address
def setTitle(self, value):
self.title = value
def setVS(self, value):
self.vs = value
def setCreator(self, value):
self.creator = value
def setPaytype(self, value):
self.paytype = value
def setPaymentDays(self, value):
self.payment_days = int(value)
def addItem(self, item):
self.items.append(item)
#############################################################
## Getters
#############################################################
def getContent(self):
# Texty
self.drawMain()
self.drawProvider(self.TOP-10,self.LEFT+3)
self.drawClient(self.TOP-30,self.LEFT+91)
self.drawPayment(self.TOP-47,self.LEFT+3)
self.drawItems(self.TOP-80,self.LEFT)
self.drawDates(self.TOP-10,self.LEFT+91)
#self.pdf.setFillColorRGB(0, 0, 0)
self.pdf.showPage()
self.pdf.save()
f = open(self.pdffile.name)
data = f.read()
f.close()
os.unlink(self.pdffile.name)
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)
#.........这里部分代码省略.........
示例6: render
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
#.........这里部分代码省略.........
s = (page_width - 2 * left_margin) / width
# center the maze, looks better for mazes that don't fit the page nicely
left_margin -= (org_width - width) * s / 2.0
top_margin -= (s * height - (page_height - 2.0 * top_margin)) / 2.0
g = s * 0.2
stroke = s / 7.0
c.setLineWidth(stroke)
k = 0.5
n = -(g / k) + 0.5 * (s - sqrt((g *
(4.0 * g - 3.0 * g * k + 2 * k * s)) / k))
r = g / k
q = n + r
v = (g * (-1 + k)) / k
theta = asin((2.0 * g - 2.0 * g * k + k * s) /
(2.0 * g - g * k + k * s)) * 180 / pi
delta = theta - 90
for j, row in enumerate(grid):
# upper/lower rows
for i, cell in enumerate(row):
x_offset = left_margin + i * s
y_offset = top_margin + j * s
c.translate(x_offset, y_offset)
p = c.beginPath()
a = g
b = s - g
# mark start and end
start = False
end = False
if (i == 0 and j == height - 1):
start = True
if (i == width - 1 and j == 0):
end = True
if start or end:
c.setStrokeColorRGB(0.9, 0.1, 0.1)
c.setFillColorRGB(0.9, 0.1, 0.1)
p.circle(s / 2.0, s / 2.0, g / 1.5)
c.drawPath(p, fill=True)
p = c.beginPath()
c.setStrokeColorRGB(0.0, 0.0, 0.0)
if cell == 3:
'│ │'
'│ │'
p.moveTo(a, s)
p.lineTo(a, 0)
p.moveTo(b, s)
p.lineTo(b, 0)
if cell == 1:
示例7: Address
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
#.........这里部分代码省略.........
self.drawDates(self.TOP-10,self.LEFT+91)
p = self.drawsItems(self.TOP-35,self.LEFT)
#self.pdf.setFillColorRGB(0, 0, 0)
self.pdf.showPage()
self.pdf.save()
f = open(self.pdffile.name)
data = f.read()
f.close()
os.unlink(self.pdffile.name)
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+65)*mm, self.TOP*mm, "Balance Sheet")
self.pdf.setFont("DejaVu", 8)
self.pdf.drawString((self.LEFT+120)*mm, (self.TOP)*mm, "Dated to: %s" % self.todate)
self.pdf.drawString((self.LEFT+120)*mm, (self.TOP+3)*mm, "Dated from: %s" % self.fromdate)
# Rámečky
#self.pdf.rect((self.LEFT)*mm, (self.TOP-38)*mm, (self.LEFT+156)*mm, 35*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-20)*mm)
self.pdf.drawPath(path, True, True)
path = self.pdf.beginPath()
path.moveTo((self.LEFT)*mm, (self.TOP-20)*mm)
path.lineTo((self.LEFT+88)*mm, (self.TOP-20)*mm)
self.pdf.drawPath(path, True, True)
path = self.pdf.beginPath()
path.moveTo((self.LEFT+88)*mm, (self.TOP-26)*mm)
path.lineTo((self.LEFT+176)*mm, (self.TOP-26)*mm)
self.pdf.drawPath(path, True, True)
path = self.pdf.beginPath()
path.moveTo((self.LEFT+88)*mm, (self.TOP-26)*mm)
path.lineTo((self.LEFT+88)*mm, (self.TOP-20)*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):
LEFT += 90
self.pdf.setFont("DejaVu", 12)
示例8: Address
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
#.........这里部分代码省略.........
# renderPDF.draw(drawing, self.pdf, self.TOP+25, self.LEFT+710)
# qrw.drawOn(self.pdf,self.TOP+45,(self.LEFT+735))
self.drawProvider(self.TOP-8,self.LEFT+3)
# self.drawClient(self.TOP-30,self.LEFT+91)
self.drawPayment(self.TOP-26,self.LEFT+3)
self.drawItems(self.TOP-45,self.LEFT)
self.drawDates(self.TOP-10,self.LEFT+91)
self.drawWatermark()
#self.pdf.setFillColorRGB(0, 0, 0)
self.pdf.showPage()
self.pdf.save()
f = open(self.pdffile.name)
data = f.read()
f.close()
os.unlink(self.pdffile.name)
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, "Invoice No.: %s" % self.vs)
# Rámečky
self.pdf.rect((self.LEFT)*mm, (self.TOP-38)*mm, (self.LEFT+156)*mm, 35*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-20)*mm)
self.pdf.drawPath(path, True, True)
path = self.pdf.beginPath()
path.moveTo((self.LEFT)*mm, (self.TOP-20)*mm)
path.lineTo((self.LEFT+88)*mm, (self.TOP-20)*mm)
self.pdf.drawPath(path, True, True)
path = self.pdf.beginPath()
path.moveTo((self.LEFT+88)*mm, (self.TOP-26)*mm)
path.lineTo((self.LEFT+176)*mm, (self.TOP-26)*mm)
self.pdf.drawPath(path, True, True)
path = self.pdf.beginPath()
path.moveTo((self.LEFT+88)*mm, (self.TOP-26)*mm)
path.lineTo((self.LEFT+88)*mm, (self.TOP-20)*mm)
self.pdf.drawPath(path, True, True)
def drawWatermark(self):
pass
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):
示例9: SimpleInvoice
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
class SimpleInvoice(BaseInvoice):
def gen(self, filename):
self.TOP = 260
self.LEFT = 20
self.filename = filename
pdfmetrics.registerFont(TTFont('DejaVu', FONT_PATH))
pdfmetrics.registerFont(TTFont('DejaVu-Bold', FONT_BOLD_PATH))
self.pdf = Canvas(self.filename, pagesize = letter)
self.addMetaInformation(self.pdf)
self.pdf.setFont('DejaVu', 15)
self.pdf.setStrokeColorRGB(0, 0, 0)
# Texty
self.drawMain()
self.drawTitle()
self.drawProvider(self.TOP - 10,self.LEFT + 3)
self.drawClient(self.TOP - 35,self.LEFT + 91)
self.drawPayment(self.TOP - 47,self.LEFT + 3)
self.drawItems(self.TOP - 80,self.LEFT)
self.drawDates(self.TOP - 10,self.LEFT + 91)
#self.pdf.setFillColorRGB(0, 0, 0)
self.pdf.showPage()
self.pdf.save()
#############################################################
## Draw methods
#############################################################
def addMetaInformation(self, pdf):
pdf.setCreator(self.invoice.provider.summary)
pdf.setTitle(self.invoice.title)
pdf.setAuthor(self.invoice.creator.name)
def drawTitle(self):
# Up line
self.pdf.drawString(self.LEFT*mm, self.TOP*mm, self.invoice.title)
self.pdf.drawString((self.LEFT + 90) * mm,
self.TOP*mm,
_(u'Variable symbol: %s') %
self.invoice.variable_symbol)
def drawMain(self):
# Borders
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 - 27) * mm)
path.lineTo((self.LEFT + 176) * mm, (self.TOP - 27) * mm)
self.pdf.drawPath(path, True, True)
def drawClient(self,TOP,LEFT):
self.pdf.setFont('DejaVu', 12)
self.pdf.drawString(LEFT * mm, TOP * mm, _(u'Customer'))
self.pdf.setFont('DejaVu', 8)
text = self.pdf.beginText((LEFT + 2) * mm, (TOP - 4) * mm)
text.textLines('\n'.join(self.invoice.client.get_address_lines()))
self.pdf.drawText(text)
text = self.pdf.beginText((LEFT + 2) * mm, (TOP - 23) * mm)
text.textLines('\n'.join(self.invoice.client.get_contact_lines()))
self.pdf.drawText(text)
if self.invoice.client.note:
self.pdf.setFont('DejaVu', 6)
text = self.pdf.beginText((LEFT + 2) * mm, (TOP - 28) * mm)
text.textLines(self.invoice.client.note)
self.pdf.drawText(text)
def drawProvider(self,TOP,LEFT):
self.pdf.setFont('DejaVu', 12)
self.pdf.drawString(LEFT * mm, TOP * mm, _(u'Provider'))
self.pdf.setFont('DejaVu', 8)
text = self.pdf.beginText((LEFT + 2) * mm, (TOP - 6) * mm)
text.textLines('\n'.join(self.invoice.provider.get_address_lines()))
self.pdf.drawText(text)
text = self.pdf.beginText((LEFT + 40) * mm, (TOP - 6) * mm)
text.textLines('\n'.join(self.invoice.provider.get_contact_lines()))
self.pdf.drawText(text)
#.........这里部分代码省略.........
示例10: PDFInvoice
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
class PDFInvoice(object):
def __init__(self, recipient, invoicedate, duedate, invoicenum=None, imagedir=None, currency='€', preview=False, receipt=False, bankinfo=True):
self.pdfdata = StringIO.StringIO()
self.canvas = Canvas(self.pdfdata)
self.recipient = recipient
self.invoicenum = invoicenum
self.invoicedate = invoicedate
self.duedate = duedate
self.imagedir = imagedir or '.'
self.currency = currency or '€'
self.preview = preview
self.receipt = receipt
self.bankinfo = bankinfo
self.rows = []
if self.receipt:
# Never include bank info on receipts
self.bankinfo = False
self.canvas.setTitle("PostgreSQL Europe Invoice #%s" % self.invoicenum)
self.canvas.setSubject("PostgreSQL Europe Invoice #%s" % self.invoicenum)
self.canvas.setAuthor("PostgreSQL Europe")
self.canvas._doc.info.producer = "PostgreSQL Europe Invoicing System"
def addrow(self, title, cost, count=1):
self.rows.append((title, cost, count,))
def trimstring(self, s, maxlen, fontname, fontsize):
while len(s) > 5:
if self.canvas.stringWidth(s, fontname, fontsize) <= maxlen:
return s
s = s[:len(s)-2]
return s
def _pageheader(self):
if self.preview:
t = self.canvas.beginText()
t.setTextOrigin(6*cm, 4*cm)
t.setFont("Times-Italic", 70)
t.setFillColorRGB(0.9,0.9,0.9)
t.textLines("PREVIEW PREVIEW")
self.canvas.rotate(45)
self.canvas.drawText(t)
self.canvas.rotate(-45)
im = Image("%s/PostgreSQL_logo.1color_blue.300x300.png" % self.imagedir, width=3*cm, height=3*cm)
im.drawOn(self.canvas, 2*cm, 25*cm)
t = self.canvas.beginText()
t.setFillColorRGB(0,0,0,0)
t.setFont("Times-Roman", 10)
t.setTextOrigin(6*cm, 27.5*cm)
t.textLines("""PostgreSQL Europe
Carpeaux Diem
13, rue du Square Carpeaux
75018 PARIS
France
""")
self.canvas.drawText(t)
t = self.canvas.beginText()
t.setTextOrigin(2*cm, 23*cm)
t.setFont("Times-Roman", 10)
t.textLine("")
t.textLines("""
Your contact: Guillaume Lelarge
Function: PostgreSQL Europe Treasurer
E-mail: [email protected]
""")
self.canvas.drawText(t)
t = self.canvas.beginText()
t.setTextOrigin(11*cm, 23*cm)
t.setFont("Times-Italic", 11)
t.textLine("To:")
t.setFont("Times-Roman", 11)
t.textLines(self.recipient)
self.canvas.drawText(t)
p = self.canvas.beginPath()
p.moveTo(2*cm, 18.9*cm)
p.lineTo(19*cm, 18.9*cm)
self.canvas.drawPath(p)
def save(self):
# We can fit 15 rows on one page. We might want to do something
# cute to avoid a single row on it's own page in the future, but
# for now, just split it evenly.
for pagenum in range(0, (len(self.rows)-1)/15+1):
self._pageheader()
islastpage = (pagenum == (len(self.rows)-1)/15)
if len(self.rows) > 15:
suffix = " (page %s/%s)" % (pagenum+1, len(self.rows)/15+1)
else:
suffix = ''
# Center between 2 and 19 is 10.5
if self.invoicenum:
#.........这里部分代码省略.........
示例11: PDFGenerator
# 需要导入模块: from reportlab.pdfgen.canvas import Canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas.Canvas import beginPath [as 别名]
#.........这里部分代码省略.........
if fill_style and fill_style[0] & sk2_const.FILL_CLOSED_ONLY and closed:
self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo)
elif fill_style and not fill_style[0] & sk2_const.FILL_CLOSED_ONLY:
self.fill_pdfpath(curve_obj, pdfpath, fill_style, curve_obj.fill_trafo)
if stroke_style and not stroke_style[7]:
self.stroke_pdfpath(pdfpath, stroke_style, curve_obj.stroke_trafo)
def draw_container(self, obj):
container = obj.childs[0].to_curve()
paths = libgeom.apply_trafo_to_paths(container.paths, container.trafo)
pdfpath, closed = self.make_pdfpath(paths)
fill_style = container.style[0]
stroke_style = container.style[1]
if stroke_style and stroke_style[7]:
self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)
self.canvas.saveState()
self.canvas.clipPath(pdfpath, 0, 0)
if fill_style and fill_style[0] & sk2_const.FILL_CLOSED_ONLY and closed:
self.fill_pdfpath(container, pdfpath, fill_style, container.fill_trafo)
elif fill_style and not fill_style[0] & sk2_const.FILL_CLOSED_ONLY:
self.fill_pdfpath(container, pdfpath, fill_style, container.fill_trafo)
self.render(obj.childs[1:])
self.canvas.restoreState()
if stroke_style and not stroke_style[7]:
self.stroke_pdfpath(pdfpath, stroke_style, container.stroke_trafo)
def make_pdfpath(self, paths):
closed = False
pdfpath = self.canvas.beginPath()
for path in paths:
pdfpath.moveTo(*path[0])
for point in path[1]:
if len(point) > 2:
pdfpath.curveTo(point[0][0], point[0][1],
point[1][0], point[1][1],
point[2][0], point[2][1])
else:
pdfpath.lineTo(*point)
if path[2]:
pdfpath.close()
closed = True
return pdfpath, closed
def set_fill_rule(self, fillrule):
if fillrule in (sk2_const.FILL_EVENODD,
sk2_const.FILL_EVENODD_CLOSED_ONLY):
fillrule = FILL_EVEN_ODD
else:fillrule = FILL_NON_ZERO
self.canvas._fillMode = fillrule
def set_rgb_values(self, color, pdfcolor):
r, g, b = self.cms.get_rgb_color(color)[1]
density = pdfcolor.density
if density < 1:
r = density * (r - 1) + 1
g = density * (g - 1) + 1
b = density * (b - 1) + 1
pdfcolor.red, pdfcolor.green, pdfcolor.blue = (r, g, b)
def get_pdfcolor(self, color):
pdfcolor = None