Simple Table
This commit is contained in:
parent
bffdbd2671
commit
c8735377a6
4 changed files with 46 additions and 10 deletions
|
@ -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.styles import ParagraphStyle, getSampleStyleSheet
|
||||||
from reportlab.lib import colors
|
from reportlab.lib import colors
|
||||||
|
|
||||||
|
@ -15,6 +15,23 @@ class CodeSnippet(Paragraph):
|
||||||
Paragraph.__init__(self, code, self.style)
|
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):
|
def __init__(self, data, horizontal_align=None):
|
||||||
Table.__init__(self, data, hAlign=horizontal_align)
|
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()
|
|
@ -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):
|
class InvoiceInfo(object):
|
||||||
"""
|
"""
|
||||||
Invoice information
|
Invoice information
|
||||||
|
|
|
@ -9,8 +9,8 @@ class SimpleInvoice(SimpleDocTemplate):
|
||||||
self,
|
self,
|
||||||
invoice_path,
|
invoice_path,
|
||||||
pagesize=letter,
|
pagesize=letter,
|
||||||
rightMargin=.25 * inch,
|
rightMargin=inch,
|
||||||
leftMargin=.25 * inch,
|
leftMargin=inch,
|
||||||
topMargin=.25 * inch,
|
topMargin=inch,
|
||||||
bottomMargin=.25 * inch
|
bottomMargin=inch
|
||||||
)
|
)
|
17
test.py
17
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
|
from pyinvoice.templates import SimpleInvoice
|
||||||
|
|
||||||
story = []
|
story = []
|
||||||
|
|
||||||
address_table = AddressTable([
|
address_table = SimpleTable([
|
||||||
['Name', 'zhangshine'],
|
['Name', 'zhangshine'],
|
||||||
|
['City', 'Jining'],
|
||||||
|
['City', 'Jining'],
|
||||||
|
['City', 'Jining'],
|
||||||
|
['City', 'Jining'],
|
||||||
['City', 'Jining']
|
['City', 'Jining']
|
||||||
], horizontal_align='RIGHT')
|
], horizontal_align='RIGHT')
|
||||||
story.append(address_table)
|
story.append(address_table)
|
||||||
|
|
||||||
|
merchant_table = SimpleTable([
|
||||||
|
['Name', 'CiCiApp'],
|
||||||
|
['xxxx', 'yyyy']
|
||||||
|
], horizontal_align='LEFT')
|
||||||
|
story.append(merchant_table)
|
||||||
|
|
||||||
doc = SimpleInvoice('test.pdf')
|
doc = SimpleInvoice('test.pdf')
|
||||||
|
|
||||||
doc.build(story)
|
doc.build(story, onFirstPage=PaidStamp(inch, 10*inch))
|
||||||
|
|
Loading…
Reference in a new issue