I'm using Reportlab to create a pdf file that can span across multiple pages with the following format:
QR code + h1 paragraph + 2-3 lines of text
We need to support a dynamic number of elements with the format I described above.
I was thinking of using a Table inside a SimpleDocTemplate but couldn't find a way to support dynamic number of elements than can span over multiple pages.
How would you tackle this challenge?
This snippet is not fully working, but it could help you, for start
class StandardReport:
def __init__(self,):
self.doc = BaseDocTemplate(destinationPath , showBoundary = 0, leftMargin=0.7*cm, rightMargin=0.7*cm, topMargin=0.7*cm, bottomMargin=0.7*cm, pagesize=A4)
self.simpleFrame = Frame(self.doc.leftMargin, self.doc.bottomMargin, self.doc.width, self.doc.height - 5*cm, id='normal')
def createPdf(self):
templates = [];
self.doc.totalPages = 0;
self.fill_sample();
templates.append(SamplePageTempalte(self));
self.doc.totalPages = self.doc.totalPages + 1;
self.doc.addPageTemplates(templates);
self.doc.build(self.Elements)
class SamplePageTempalte (PageTemplate):
def __init__ (self, context):
self.context = context
self.largeur = self.context.doc.pagesize[0]
self.hauteur = self.context.doc.pagesize[1]
self.simpleFrame = Frame( self.context.doc.leftMargin, self.context.doc.bottomMargin, self.context.doc.width, self.context.doc.height - 3*cm, id='normal')
PageTemplate.__init__ (self, id="GraphStatPageTemplateMonth", frames = [self.simpleFrame], pagesize=A4, onPage = self.context.footerAndHeader)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.