From e40c3927613800d0c386b92738a9484b79f3d820 Mon Sep 17 00:00:00 2001 From: zhangshine Date: Sat, 30 May 2015 21:15:47 +0800 Subject: [PATCH] PaidStamp --- pyinvoice/components.py | 14 ++++++++++++-- test.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pyinvoice/components.py b/pyinvoice/components.py index 2f3121c..e2f81b1 100644 --- a/pyinvoice/components.py +++ b/pyinvoice/components.py @@ -1,4 +1,7 @@ -from reportlab.platypus import Paragraph, Table, TableStyle, Flowable +from reportlab.graphics.charts.textlabels import Label +from reportlab.graphics.shapes import Drawing +from reportlab.lib.units import inch +from reportlab.platypus import Paragraph, Table, TableStyle from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet from reportlab.lib import colors @@ -31,7 +34,14 @@ class PaidStamp(object): self.y = y def __call__(self, canvas, doc): - # TODO: xxx + # "PAID" canvas.saveState() + canvas.setFontSize(50) + canvas.setFillColor(colors.red) + canvas.setStrokeColor(colors.red) + canvas.rotate(45) canvas.drawString(self.x, self.y, 'PAID') + canvas.setLineWidth(4) + canvas.setLineJoin(1) # Round join + canvas.rect(self.x - .25 * inch, self.y - .25 * inch, width=2*inch, height=inch) canvas.restoreState() \ No newline at end of file diff --git a/test.py b/test.py index 6cdb2a0..d17257d 100644 --- a/test.py +++ b/test.py @@ -22,4 +22,4 @@ story.append(merchant_table) doc = SimpleInvoice('test.pdf') -doc.build(story, onFirstPage=PaidStamp(inch, 10*inch)) +doc.build(story, onFirstPage=PaidStamp(7*inch, 5.8*inch))