I have a list of records on database those I want print on pdf (sales).
Each record (sale) contains a list of other records (products).
I want to print three column in each sheet.
To do this, I'm using Frames.
So far, its ok. Each sale with all products are printed on the frame, when the products of the sale finish, I use FrameBreak() to go to another frame.
After print, I cut each frame as a piece of paper to show to the client.
Now I'm having a problem. When the sale has many products, its use other frame. Then, whem I cut the paper, there is no way to sure what piece of paper must be joined.
Is therea way to put the sale ID in the header and footer to each Frame?
Is there another way to solve this problem?
To exemplify:
from reportlab.lib.pagesizes import landscape, letter
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import BaseDocTemplate, Frame, Paragraph, PageTemplate
from reportlab.platypus.doctemplate import FrameBreak
p = 'Product---------------10un---------------10,00 <br />'
class sale():
id = None
client = None
products = None
s1 = sale()
s1.id = 1
s1.client = 'Client name 1'
s1.products=p*60
s2 = sale()
s2.id = 2
s2.client = 'Client name 2'
s2.products=p*48
s3 = sale()
s3.id = 3
s3.client = 'Client name 3'
s3.products=p*60
s4 = sale()
s4.id = 4
s4.client = 'Client name 4'
s4.products=p*48
Elements=[]
doc = BaseDocTemplate('basedoc.pdf',showBoundary=1,pagesize=landscape(letter),leftMargin=5, rightMargin=5, topMargin=5, bottomMargin=5)
styles = getSampleStyleSheet()
#3 Columns
frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/3, doc.height, id='col1')
frame2 = Frame(doc.leftMargin+doc.width/3, doc.bottomMargin, doc.width/3, doc.height, id='col2')
frame3 = Frame(doc.leftMargin+(doc.width/3)*2, doc.bottomMargin, doc.width/3, doc.height, id='col3')
Elements.append(Paragraph('<b> Sale ID: %s</b>'%s1.id,styles['Normal']))
Elements.append(Paragraph('<b> Client Name: ' + s1.client + '</b>',styles['Normal']))
Elements.append(Paragraph(s1.products, styles['Normal']))
Elements.append(FrameBreak())
Elements.append(Paragraph('<b> Sale ID: %s</b>'%s2.id,styles['Normal']))
Elements.append(Paragraph('<b> Client Name: ' + s2.client + '</b>',styles['Normal']))
Elements.append(Paragraph(s2.products, styles['Normal']))
Elements.append(FrameBreak())
Elements.append(Paragraph('<b> Sale ID: %s</b>'%s3.id,styles['Normal']))
Elements.append(Paragraph('<b> Client Name: ' + s3.client + '</b>',styles['Normal']))
Elements.append(Paragraph(s3.products, styles['Normal']))
Elements.append(FrameBreak())
Elements.append(Paragraph('<b> Sale ID: %s</b>'%s4.id,styles['Normal']))
Elements.append(Paragraph('<b> Client Name: ' + s4.client + '</b>',styles['Normal']))
Elements.append(Paragraph(s4.products, styles['Normal']))
Elements.append(FrameBreak())
doc.addPageTemplates([PageTemplate(id='cols',frames=[frame1,frame2,frame3]), ])
doc.build(Elements)