From bffdbd267139314bcd044b78d525711c50fae5ab Mon Sep 17 00:00:00 2001 From: zhangshine Date: Thu, 28 May 2015 01:09:44 +0800 Subject: [PATCH] Simple address table --- pyinvoice/components.py | 7 ++++++- pyinvoice/templates.py | 16 ++++++++++++++++ test.py | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 pyinvoice/templates.py create mode 100644 test.py diff --git a/pyinvoice/components.py b/pyinvoice/components.py index 4966333..f40c355 100644 --- a/pyinvoice/components.py +++ b/pyinvoice/components.py @@ -12,4 +12,9 @@ class CodeSnippet(Paragraph): ) def __init__(self, code): - Paragraph.__init__(self, code, self.style) \ No newline at end of file + Paragraph.__init__(self, code, self.style) + + +class AddressTable(Table): + def __init__(self, data, horizontal_align=None): + Table.__init__(self, data, hAlign=horizontal_align) \ No newline at end of file diff --git a/pyinvoice/templates.py b/pyinvoice/templates.py new file mode 100644 index 0000000..93cf667 --- /dev/null +++ b/pyinvoice/templates.py @@ -0,0 +1,16 @@ +from reportlab.lib.pagesizes import letter +from reportlab.lib.units import inch +from reportlab.platypus import SimpleDocTemplate + + +class SimpleInvoice(SimpleDocTemplate): + def __init__(self, invoice_path): + SimpleDocTemplate.__init__( + self, + invoice_path, + pagesize=letter, + rightMargin=.25 * inch, + leftMargin=.25 * inch, + topMargin=.25 * inch, + bottomMargin=.25 * inch + ) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..b8e2d22 --- /dev/null +++ b/test.py @@ -0,0 +1,14 @@ +from pyinvoice.components import AddressTable +from pyinvoice.templates import SimpleInvoice + +story = [] + +address_table = AddressTable([ + ['Name', 'zhangshine'], + ['City', 'Jining'] +], horizontal_align='RIGHT') +story.append(address_table) + +doc = SimpleInvoice('test.pdf') + +doc.build(story)