From c8735377a60e7314616ab5cccd62b15306600370 Mon Sep 17 00:00:00 2001 From: zhangshine Date: Thu, 28 May 2015 18:17:55 +0800 Subject: [PATCH] Simple Table --- pyinvoice/components.py | 23 ++++++++++++++++++++--- pyinvoice/models.py | 8 ++++++++ pyinvoice/templates.py | 8 ++++---- test.py | 17 ++++++++++++++--- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/pyinvoice/components.py b/pyinvoice/components.py index f40c355..2f3121c 100644 --- a/pyinvoice/components.py +++ b/pyinvoice/components.py @@ -1,4 +1,4 @@ -from reportlab.platypus import Paragraph, Table +from reportlab.platypus import Paragraph, Table, TableStyle, Flowable from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet from reportlab.lib import colors @@ -15,6 +15,23 @@ class CodeSnippet(Paragraph): Paragraph.__init__(self, code, self.style) -class AddressTable(Table): +class SimpleTable(Table): + style = TableStyle([ + ('INNERGRID', (0, 0), (-1, -1), .25, colors.black), + ('BOX', (0, 0), (-1, -1), .25, colors.black), + ]) + def __init__(self, data, horizontal_align=None): - Table.__init__(self, data, hAlign=horizontal_align) \ No newline at end of file + Table.__init__(self, data, style=self.style, hAlign=horizontal_align) + + +class PaidStamp(object): + def __init__(self, x, y): + self.x = x + self.y = y + + def __call__(self, canvas, doc): + # TODO: xxx + canvas.saveState() + canvas.drawString(self.x, self.y, 'PAID') + canvas.restoreState() \ No newline at end of file diff --git a/pyinvoice/models.py b/pyinvoice/models.py index 14eb11b..a54f926 100644 --- a/pyinvoice/models.py +++ b/pyinvoice/models.py @@ -1,3 +1,11 @@ +class PDFInfo(object): + def __init__(self, title, author, subject): + self.title = title + self.author = author + self.subject = subject + self.creator = 'pyinvlice (https://ciciapp.com/pyinvoice)' + + class InvoiceInfo(object): """ Invoice information diff --git a/pyinvoice/templates.py b/pyinvoice/templates.py index 93cf667..5d299d7 100644 --- a/pyinvoice/templates.py +++ b/pyinvoice/templates.py @@ -9,8 +9,8 @@ class SimpleInvoice(SimpleDocTemplate): self, invoice_path, pagesize=letter, - rightMargin=.25 * inch, - leftMargin=.25 * inch, - topMargin=.25 * inch, - bottomMargin=.25 * inch + rightMargin=inch, + leftMargin=inch, + topMargin=inch, + bottomMargin=inch ) \ No newline at end of file diff --git a/test.py b/test.py index b8e2d22..6cdb2a0 100644 --- a/test.py +++ b/test.py @@ -1,14 +1,25 @@ -from pyinvoice.components import AddressTable +from reportlab.lib.units import inch +from pyinvoice.components import SimpleTable, PaidStamp from pyinvoice.templates import SimpleInvoice story = [] -address_table = AddressTable([ +address_table = SimpleTable([ ['Name', 'zhangshine'], + ['City', 'Jining'], + ['City', 'Jining'], + ['City', 'Jining'], + ['City', 'Jining'], ['City', 'Jining'] ], horizontal_align='RIGHT') story.append(address_table) +merchant_table = SimpleTable([ + ['Name', 'CiCiApp'], + ['xxxx', 'yyyy'] +], horizontal_align='LEFT') +story.append(merchant_table) + doc = SimpleInvoice('test.pdf') -doc.build(story) +doc.build(story, onFirstPage=PaidStamp(inch, 10*inch))