def story_title(survey, info=dict()): story = [ platypus.Paragraph(str(line), stylesheet['Title']) for line in survey.title.split('\n') ] story += [ platypus.FrameBreak(), ] keys = list(survey.info.keys()) if keys: keys.sort() table = [[ platypus.Paragraph(str(key), stylesheet['Normal']), platypus.Paragraph(str(survey.info[key]), stylesheet['Normal']) ] for key in keys] story += [ platypus.Table(table, colWidths=(50 * mm, None)), ] if info: story += [platypus.Spacer(0, 10 * mm)] keys = list(info.keys()) keys.sort() table = [[ platypus.Paragraph(str(key), stylesheet['Normal']), platypus.Paragraph(str(info[key]), stylesheet['Normal']) ] for key in keys] story += [ platypus.Table(table, colWidths=(50 * mm, None)), ] story += [platypus.NextPageTemplate('Normal'), platypus.PageBreak()] return story
def _create(self): """ Does the final creation of the Platypus Table object. Including a correct numeration for the Table of Tables list. Typically this Method will be called by the _PreBuild-Method of the Story class. :return: story with all final objects for pdf rendering :rtype: list of platypus objects ready for rendering. """ story = [] data = [] if self._header is not None: data.append(build_table_header(self._header)) if self._cellstyle: data += [ build_table_row(f, style=self._cellstyle) for f in self._data ] else: data += self._data table = plat.Table(data, repeatRows=1, **self._kwargs) table.keepWithNext = True story.append(plat.Spacer(1, 0.2 * cm)) story.append(table) # story.append(plat.Spacer(1, 1 * cm)) self.append_caption(story) return story
def print_employees_badges(dao): global header_text global sub_header_text header_text = "" sub_header_text = _("Employees badges") s = ParagraphStyle(name="zou", fontName='Helvetica', alignment=TA_CENTER) badges_per_line = 3 array = [] row = [] employees = dao.employee_dao.all() if len(employees) == 0: return i = 0 for employee in employees: row.append([ Paragraph(employee.fullname, s), platypus.Spacer(0, 0.25 * cm), createBarcodeDrawing('EAN13', value=str( BarCodeIdentifier.code_for(employee)), barHeight=1 * cm) ]) i = i + 1 if i == badges_per_line: array.append(row) row = [] i = 0 if i > 0: array.append(row) t = platypus.Table(array, repeatRows=0, colWidths=[6 * cm] * badges_per_line, rowHeights=[3 * cm] * len(array)) # Repeat the table header ts = platypus.TableStyle([('FONT', (0, 0), (-1, -1), 'Helvetica', 8)]) ts.add('ALIGN', (0, 0), (-1, -1), 'CENTER') ts.add('VALIGN', (0, 0), (-1, -1), 'MIDDLE') ts.add("LEFTPADDING", (0, 0), (-1, -1), 0) ts.add("RIGHTPADDING", (0, 0), (-1, -1), 0) ts.add('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black) ts.add('BOX', (0, 0), (-1, -1), 0.25, colors.black) t.setStyle(ts) complete_document = [] complete_document.append(t) filename = make_pdf_filename("EmployeeBadges") ladderDoc = start_PDF(filename) ladderDoc.build(complete_document, canvasmaker=NumberedCanvas) open_pdf(filename)