def add_catalog_title(self, title): # self.obj.append(BookMark(title, level=0)) self.obj.append(Paragraph('<b>' + title + '</b>', headstyle)) toc = TableOfContents() toc.levelStyles = [ PS(fontName='song', fontSize=10, name='TOCHeading1', leftIndent=10, firstLineIndent=-20, spaceBefore=0, leading=12), PS(fontName='song', fontSize=10, name='TOCHeading2', leftIndent=20, firstLineIndent=-20, spaceBefore=0, leading=12), PS(fontName='song', fontSize=10, name='TOCHeading3', leftIndent=30, firstLineIndent=-20, spaceBefore=0, leading=12), ] self.obj.append(toc)
def __init__(self, output_file: str, **kwargs): """ Constructor for the PDF Creator class """ # Check for stray kwargs if kwargs: raise TypeError("got an unexpected keyword argument '%s'" % list(kwargs.keys())[0]) # Define variables used during creation global doc, elements, styleSheet, doc_color global table_data_reg_list, table_data_field_list, toc # Create the document doc = MySimpleDocTemplate(output_file, pagesize=A4) # container for the 'Flowable' objects elements = [] ## Table data table_data_reg_list = [] table_data_field_list = [] # Document color #doc_color = darkgrey #doc_color = dimgrey #doc_color = black doc_color = colors.HexColor(0x24001e) # Create the style sheet styleSheet = getSampleStyleSheet() # Add more custom styles self.add_more_styles() # First page elements.append(PageBreak()) # TOC h1 = ParagraphStyle(name = 'Heading1', fontName=_baseFontNameB, textColor=doc_color, fontSize = 14, spaceBefore=10, leading = 16) h2 = ParagraphStyle(name = 'Heading2', fontName=_baseFontName, textColor=doc_color, fontSize = 12, leading = 14) # Table of contents toc = TableOfContents() toc.levelStyles = [h1, h2] elements.append(Paragraph('Table of Contents', styleSheet["Header1Toc"])) elements.append(Spacer(1, 1*inch)) elements.append(toc) elements.append(PageBreak())
def main(): with open(JSON_PATH) as file: # Read and parse JSON file data = json.loads(file.read()) # Default pdf values doc = MyDocTemplate(PDF_PATH) toc = TableOfContents() toc.levelStyles = [ ParagraphStyle(name="Heading1", fontSize=14, leading=16), ParagraphStyle(name="Heading2", fontSize=12, leading=14, leftIndent=10), ParagraphStyle(name="Heading3", fontSize=10, leading=12, leftIndent=20), ] elements = [ Paragraph("PEAS Report", style=styles["Title"]), Spacer(0, 30), toc, PageBreak() ] # Iterate over all top level sections and build their elements. for title in data.keys(): element_list = build_main_section(data[title], title) elements.extend(element_list) doc.multiBuild(elements)
def ReportGen(request, owner_name): buff=StringIO() response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=ReportOnShaastra.pdf' sno=1 elements=[] toc = TableOfContents() # For conciseness we use the same styles for headings and TOC entries toc.levelStyles = [h1, h2] elements.append(Paragraph('Shaastra Report',centered)) elements.append(Paragraph('Table Of Contents',centered)) elements.append(toc) elements.append(PageBreak()) position_on_page=PAGE_HEIGHT-FRAME_BORDER users_in_department=userprofile.objects.filter(department = request.user.get_profile().department ) if is_core(request.user): tasks=Task.objects.filter(creator__in = users_in_department ).order_by('creation_date') elements.append(Paragraph('Tasks made by your Department',h1)) elements.append(big_spacer) position_on_page = position_on_page - h1.fontSize - big_spacer_height for task in tasks: position_on_page,sno=ShowTask(request,elements,position_on_page,sno,task) elements.append(PageBreak()) position_on_page=PAGE_HEIGHT-FRAME_BORDER elements.append(Paragraph('SubTasks given to your Department',h1)) elements.append(big_spacer) tasks=SubTask.objects.filter(department = request.user.get_profile().department ).order_by('creation_date') position_on_page = position_on_page - h1.fontSize - big_spacer_height for task in tasks: position_on_page,sno=ShowSubTask(request,elements,position_on_page,sno,task) elements.append(PageBreak()) position_on_page=PAGE_HEIGHT-FRAME_BORDER sno=1 if is_core(request.user): subtasks=SubTask.objects.filter(creator__in = users_in_department).order_by('creation_date') elements.append(Paragraph('Sub-Tasks given to your coords',h1)) elements.append(big_spacer) position_on_page = position_on_page - h1.fontSize - big_spacer_height elif is_coord(request.user): subtasks = request.user.subtask_set.all().order_by('creation_date') elements.append(Paragraph('Sub-Tasks given to you',h1)) elements.append(big_spacer) position_on_page = position_on_page - h1.fontSize - big_spacer_height for subtask in subtasks: position_on_page,sno=ShowSubTask(request,elements,position_on_page,sno,subtask) doc = MyDocTemplate(buff) doc.multiBuild(elements) response.write(buff.getvalue()) return response
def gen_pdf(generator, output, toc=True): addMapping(DEFAULT_FONT, 1, 1, DEFAULT_FONT) story = [] if toc: title_style = ParagraphStyle(fontName=DEFAULT_FONT, fontSize=15, name='TOC', spaceAfter=10) story.append(Paragraph('目次', title_style)) toc = TableOfContents() toc.levelStyles = [ ParagraphStyle(fontName=DEFAULT_FONT, fontSize=8, name='body', spaceAfter=4, justifyBreaks=1) ] story.append(toc) story.append(PageBreak()) story.extend(generator.convert()) doc = DocTemplate(output) pdfmetrics.registerFont(TTFont(DEFAULT_FONT, DEFAULT_FONT_FILE)) doc.multiBuild(story)
def generate(self, report_elements=[]): elements = [] h1 = ParagraphStyle(name='Heading1', fontSize=14, leading=16) h2 = ParagraphStyle(name='Heading2', fontSize=12, leading=14, leftIndent=5) # First page elements.append(Paragraph("", self.styles['Normal'])) elements.append(NextPageTemplate('OneCol')) elements.append(PageBreak()) self.add_title(elements, "Table of contents") toc = TableOfContents() # For conciseness we use the same styles for headings and TOC entries toc.levelStyles = [h1, h2] elements.append(toc) elements.append(PageBreak()) if len(report_elements) > 0: elements.extend(report_elements) self.add_title(elements, "Organisation") elements.append(self.last_page()) elements.append(PageBreak()) self.multiBuild(elements)
def create_toc(): """Creates the table of contents""" table_of_contents = TableOfContents() table_of_contents.dotsMinLevel = 0 header1 = ParagraphStyle(name='Heading1', fontSize=16, leading=16) header2 = ParagraphStyle(name='Heading2', fontSize=14, leading=14) table_of_contents.levelStyles = [header1, header2] return [table_of_contents, PageBreak()]
def appendToc(self): toc = TableOfContents() toc.levelStyles = [self.document.styles['TOCHeading1'], self.document.styles['TOCHeading2'], self.document.styles['TOCHeading3'], self.document.styles['TOCHeading4'] ] self.document.append(toc)
def add_toc(): toc = TableOfContents() toc.levelStyles = [ PS(fontName='Times-Bold', fontSize=20, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=10, leading=16), PS(fontSize=18, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=5, leading=12), ] story.append(toc) story.append(Paragraph('<b>Table of contents</b>', centered)) story.append(PageBreak())
def event_go(self): story = list() # 报告内容存储结构 story.append(PageBreak()) # 目录 toc = TableOfContents() toc.dotsMinLevel = 0 toc.levelStyles = [H1, H2, H3] story.append(Paragraph('目录', toc1)) story.append(toc) # 分页 story.append(PageBreak()) add_title(story, '1 前言', h1) add_title(story, '1.1 报告阅读说明', h2) story.append( Paragraph( '本报告是安全事件情况的统计,主要内容包含攻击源/目标TOP5,安全事件协议分布,安全事件来源分布,' '以及安全事件总数随时间分布趋势。', body)) story.append(Paragraph('北京天地和兴科技有限公司感谢您对我们的信任和支持。现将安全事件报告呈上。', body)) if self.report_method in [1, 2, 3]: add_title(story, '1.2 周期性报表', h2) else: add_title(story, '1.2 自定义报表', h2) self.base_info_table(story) story.append(PageBreak()) story.append(Paragraph('2 安全事件概述', h1)) add_title(story, '2.1 源地址top5', h2) self.src_table(story) add_title(story, '2.2 目的地址top5', h2) self.dst_table(story) story.append(PageBreak()) add_title(story, '2.3 安全事件协议类型分布图', h2) self.event_proto_figure(story) story.append(PageBreak()) add_title(story, '2.4 安全事件来源分布图', h2) self.event_src_figure(story) add_title(story, '2.5 事件时间分布趋势图', h2) self.event_time(story) story.append(PageBreak()) # about_us_3(story) try: doc = MyDocTemplate(path + '/pdf_tmp/event_report.pdf') logger.info( "====================enter event report multiBuild............." ) doc.multiBuild(story, onFirstPage=firstPages, onLaterPages=laterPages) os.system("rm -rf " + path + "/tmp/") os.system("mv " + path + "/pdf_tmp/event_report.pdf " + "/data/report/alarm/") except: logger.error("MyDocTemplate build error.") logger.error(traceback.format_exc())
def getTabelOfContents(): """ returns toc with 3 customized headings """ toc = TableOfContents() toc.levelStyles = [ PS(fontSize=12, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=6, leading=14), #fontName='Times-Bold', PS(fontSize=10, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=4, leading=12), PS(fontSize=8, name='TOCHeading3', leftIndent=50, firstLineIndent=-20, spaceBefore=2, leading=10), ] return toc
def process(self, block, context): toc = TableOfContents() toc.dotsMinLevel = 0 toc.levelStyles = [ context.styleSheet["Toc0"], context.styleSheet["Toc1"], context.styleSheet["Toc2"], context.styleSheet["Toc3"] ] content = [] content.append(toc) return content
def simple_toc(): doc = SimpleDocTemplate("Ejemplo11.pdf") story = [] styles = getSampleStyleSheet() toc = TableOfContents() toc.levelStyles = [ ParagraphStyle(fontName='Helvetica', fontSize=14, name='Heading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=16), ParagraphStyle(fontName='Times-Roman', fontSize=14, name='Heading2', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=16), ] story.append(toc) ipsum = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.''' para = Paragraph("The Beginning", style=styles['Heading1']) toc.addEntry(0, 'The Beginning', 1) story.append(para) para = Paragraph(ipsum, style=styles['Normal']) story.append(para) story.append(PageBreak()) para = Paragraph("The Middle", style=styles['Heading1']) toc.addEntry(0, 'The Middle', 2) story.append(para) para = Paragraph("The Middle Sub-Header", style=styles['Heading2']) toc.addEntry(1, 'The Middle Sub-Header', 2) story.append(para) para = Paragraph(ipsum, style=styles['Normal']) story.append(para) story.append(PageBreak()) para = Paragraph("The End", style=styles['Heading1']) toc.addEntry(0, 'The End', 3) story.append(para) doc.multiBuild(story)
def doTableOfContents(): toc = TableOfContents() toc.levelStyles = [ PS(fontName='Times-Bold', fontSize=14, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, leading=14), PS(fontSize=12, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, leading=12), ] text = 'Table of contents' doHeading( text, PS(name = 'Heading1', fontName='Times-Bold', fontSize = 18, alignment = 1, leading = 16 )) story.append(Spacer(1,6)) story.append(toc) story.append(PageBreak())
def main(): try: path_omd = Path("%s/git/check_mk/omd/" % Path.home()) path_license_texts = path_omd / "license_sources/license_texts/" path_pdf = path_omd / "License_texts.pdf" path_cover = path_omd / "license_sources/licenses_cover.pdf" except: raise OSError registerFont(TTFont('Calibri', 'Calibri.ttf')) doc = SimpleDocTemplate( str(path_pdf), pagesize=letter, bottomMargin=.4 * inch, topMargin=.6 * inch, rightMargin=.8 * inch, leftMargin=.8 * inch) toc = TableOfContents() toc.levelStyles = [ PS(fontName='Calibri', fontSize=14, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=16), PS(fontSize=12, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, leading=12), ] title = PS(name='Title', fontSize=24, leading=16) h1 = PS(name='Heading1', fontSize=16, leading=16) normal = PS(name='Normal', fontSize=8) spacer = Spacer(width=0, height=2 * cm) story = [] story.append(Paragraph('<b>Content</b>', title)) story.append(spacer) story.append(toc) for file_path in sorted(path_license_texts.iterdir()): with file_path.open(encoding="utf-8") as txt_file: headline = "<b>%s</b>" % txt_file.readline().replace("\n", "<br /><br />\n") text_content = txt_file.read().replace("\n", "<br />\n") story.append(PageBreak()) story.append(heading(headline, h1)) story.append(Paragraph(text_content, normal)) doc = MyDocTemplate(str(path_pdf)) doc.multiBuild(story) pdf_merger = PdfFileMerger() pdf_merger.append(PdfFileReader(str(path_cover))) pdf_merger.append(PdfFileReader(str(path_pdf))) pdf_merger.write(str(path_pdf))
def test0(self): """Test story with TOC and a cascaded header hierarchy. The story should contain exactly one table of contents that is immediatly followed by a list of of cascaded levels of header lines, each nested one level deeper than the previous one. Features to be visually confirmed by a human being are: 1. TOC lines are indented in multiples of 1 cm. 2. Wrapped TOC lines continue with additional 0.5 cm indentation. 3. ... """ maxLevels = 12 # Create styles to be used for document headers # on differnet levels. headerLevelStyles = [] for i in range(maxLevels): headerLevelStyles.append(makeHeaderStyle(i)) # Create styles to be used for TOC entry lines # for headers on differnet levels. tocLevelStyles = [] d, e = tableofcontents.delta, tableofcontents.epsilon for i in range(maxLevels): tocLevelStyles.append(makeTocHeaderStyle(i, d, e)) # Build story. story = [] styleSheet = getSampleStyleSheet() bt = styleSheet['BodyText'] description = '<font color=red>%s</font>' % self.test0.__doc__ story.append(XPreformatted(description, bt)) toc = TableOfContents() toc.levelStyles = tocLevelStyles story.append(toc) for i in range(maxLevels): story.append(Paragraph('HEADER, LEVEL %d' % i, headerLevelStyles[i])) #now put some body stuff in. txt = randomtext.randomText(randomtext.PYTHON, 5) para = Paragraph(txt, makeBodyStyle()) story.append(para) path = outputfile('test_platypus_toc.pdf') doc = MyDocTemplate(path) doc.multiBuild(story)
def proto_go(self): story = list() # 报告内容存储结构 story.append(PageBreak()) # 目录 toc = TableOfContents() toc.dotsMinLevel = 0 toc.levelStyles = [H1, H2, H3] story.append(Paragraph('目录', toc1)) story.append(toc) # 分页 story.append(PageBreak()) add_title(story, '1 前言', h1) add_title(story, '1.1 报告阅读说明', h2) story.append( Paragraph('本报告是协议审计情况的统计,主要内容包含协议类型分布,TOP特征值展示,' '以及协议数随时间分布趋势。', body)) story.append(Paragraph('北京天地和兴科技有限公司感谢您对我们的信任和支持。现将安全审计报告呈上。', body)) if self.report_method in [1, 2, 3]: add_title(story, '1.2 周期性报表', h2) else: add_title(story, '1.2 自定义报表', h2) self.base_info_table(story) story.append(PageBreak()) story.append(Paragraph('2 审计概述', h1)) add_title(story, '2.1 协议类型分布图', h2) self.proto_figure(story) add_title(story, '2.2 源地址-目的地址top5', h2) self.src_dst_table(story) story.append(PageBreak()) add_title(story, '2.3 协议时间分布趋势图', h2) self.proto_time(story) # add_title(story, '2.4 传输层分布', h2) # self.l2_figure(story) # story.append(PageBreak()) # about_us_3(story) try: doc = MyDocTemplate(path + '/pdf_tmp/audit_report.pdf') logger.info( "====================enter proto report multiBuild............." ) doc.multiBuild(story, onFirstPage=firstPages, onLaterPages=laterPages) os.system("rm -rf " + path + "/tmp/") os.system("mv " + path + "/pdf_tmp/audit_report.pdf " + "/data/report/protocal/") except: logger.error("MyDocTemplate build error.") logger.error(traceback.format_exc())
def add_table_of_contents(self): """ :param self: :return TOC : """ self.add_heading('Table of Contents', htmltag='centered-bold') toc = TableOfContents() toc.levelStyles = [ PS(fontName='Times-Bold', fontSize=18, name='TOCHeading1', leftIndent=10, firstLineIndent=-15, spaceBefore=10, leading=16), PS(fontName='Times-Italic',fontSize=16, name='TOCHeading2', leftIndent=22, firstLineIndent=-15, spaceBefore=5, leading=12), PS(fontName='Times-Italic',fontSize=14, name='TOCHeading3', leftIndent=34, firstLineIndent=-15, spaceBefore=5, leading=12), PS(fontName='Times-Italic',fontSize=12, name='TOCHeading4', leftIndent=46, firstLineIndent=-15, spaceBefore=5, leading=12) ] self.flowables.append(toc)
def set_toc(self): # Create an instance of TableOfContents. Override the level styles (optional) # and add the object to the story toc = TableOfContents() toc.levelStyles = [ PS(fontSize=12, name='TOCHeading1', leftIndent=0, firstLineIndent=-20, spaceBefore=0, leading=10), PS(fontSize=11, name='TOCHeading2', leftIndent=10, firstLineIndent=-20, spaceBefore=0, leading=10), PS(fontSize=10, name='TOCHeading3', leftIndent=20, firstLineIndent=-20, spaceBefore=0, leading=10), PS(fontSize=9, name='TOCHeading4', leftIndent=30, firstLineIndent=-20, spaceBefore=0, leading=10), PS(fontSize=8, name='TOCHeading5', leftIndent=40, firstLineIndent=-20, spaceBefore=0, leading=10), ] self.elements.append(Paragraph(self.title, self.style['centered'])) #self.elements.append(Paragraph(_("Organization: <b>%s</b>") % self.org.name, self.style[1])) self.elements.append(toc) self.elements.append(PageBreak())
def assets_go(self): story = list() # 报告内容存储结构 story.append(PageBreak()) # 目录 toc = TableOfContents() toc.dotsMinLevel = 0 toc.levelStyles = [H1, H2, H3] story.append(Paragraph('目录', toc1)) story.append(toc) # 分页 story.append(PageBreak()) add_title(story, '1 前言', h1) add_title(story, '1.1 报告阅读说明', h2) story.append( Paragraph('本报告是资产报告情况的统计,设备在线统计分布,设备类型统计分布,设备身份状态统计分布。', body)) story.append(Paragraph('北京天地和兴科技有限公司感谢您对我们的信任和支持,现将资产报告呈上。', body)) if self.report_method in [1, 2, 3]: add_title(story, '1.2 周期性报表', h2) else: add_title(story, '1.2 自定义报表', h2) self.base_info_table(story) story.append(PageBreak()) story.append(Paragraph('2 资产报告概述', h1)) add_title(story, '2.1 设备在线数量分布图', h2) self.assets_live(story) story.append(PageBreak()) add_title(story, '2.2 设备类型分布图', h2) self.assets_type(story) story.append(PageBreak()) add_title(story, '2.3 设备身份状态分布图', h2) self.assets_status(story) try: doc = MyDocTemplate(path + '/pdf_tmp/assets_report.pdf') logger.info( "====================enter assets report multiBuild............." ) doc.multiBuild(story, onFirstPage=firstPages, onLaterPages=laterPages) os.system("rm -rf " + path + "/tmp/") os.system("mv " + path + "/pdf_tmp/assets_report.pdf " + "/data/report/assets/") except: logger.error("MyDocTemplate build error.") logger.error(traceback.format_exc())
def armar_pdf(): centered = PS(name = 'centered', fontSize = 30, leading = 16, alignment = 1, spaceAfter = 20) h1 = PS( name = 'Heading1', fontSize = 14, leading = 16) h2 = PS(name = 'Heading2', fontSize = 12, leading = 14) # Build story. story = [] # Create an instance of TableOfContents. Override the level styles (optional) # and add the object to the story toc = TableOfContents() toc.levelStyles = [ PS(fontName='Times-Bold', fontSize=20, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=10, leading=16), PS(fontSize=18, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=5, leading=12), ] story.append(toc) story.append(Paragraph('<b>Table of contents</b>', centered)) story.append(PageBreak()) story.append(Paragraph('First heading', h1)) story.append(Paragraph('Text in first heading', PS('body'))) story.append(Paragraph('First sub heading', h2)) story.append(Paragraph('Text in first sub heading', PS('body'))) story.append(PageBreak()) story.append(Paragraph('Second sub heading', h2)) story.append(Paragraph('Text in second sub heading', PS('body'))) story.append(PageBreak()) story.append(Paragraph('Last heading', h1)) doc = MyDocTemplate('mintoc.pdf') doc.multiBuild(story)
def pagecat(request): pdf1 = "pdf1.pdf" pdf2 = "pdf2.pdf" pdfs = [pdf1, pdf2] # Story = [] centered = ParagraphStyle(name='centered', fontSize=30, leading=16, alignment=1, spaceAfter=20) h1 = ParagraphStyle( name='Heading1', fontSize=14, leading=16) h2 = ParagraphStyle(name='Heading2', fontSize=12, leading=14) toc = TableOfContents() toc.levelStyles = [ ParagraphStyle(fontName='Times-Bold', fontSize=20, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=10, leading=16), ParagraphStyle(fontSize=18, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=5, leading=12), ] Story.append(toc) manual_toc = True if manual_toc: cpt = 0 Story.append(Paragraph('<b>Table of contents</b>', centered)) for fname in pdfs: Story.append(Paragraph('<includePdfPages filename="%s" pages="1" outlineText="crasher"/>' % fname, h1)) Story.append(Paragraph('%s' % fname, h2)) cpt = cpt + 1 doc = MyDocTemplate('mintoc.pdf') doc.multiBuild(Story) return render(request, "test.html")
def test0(self): h1 = PS(name='Heading1', fontSize=14, leading=16) h2 = PS(name='Heading2', fontSize=12, leading=14, leftIndent=2 * cm) # Build story. story = [] toc = TableOfContents() # For conciseness we use the same styles for headings and TOC entries toc.levelStyles = [h1, h2] story.append(toc) story.append(PageBreak()) story.append(Paragraph('First heading', h1)) story.append(Paragraph('Text in first heading', PS('body'))) story.append(Paragraph('First sub heading', h2)) story.append(Paragraph('Text in first sub heading', PS('body'))) story.append(PageBreak()) story.append(Paragraph('Second sub heading', h2)) story.append(Paragraph('Text in second sub heading', PS('body'))) story.append(Paragraph('Last heading', h1)) doc = MyDocTemplate(outputfile('test_multibuild.pdf')) doc.multiBuild(story)
def main(): heading1_style = ParagraphStyle(name='Heading1', fontSize=16, leading=16) heading2_style = ParagraphStyle( name='Heading2', fontSize=12, leading=14, ) # create story and table of contents object story = [] toc = TableOfContents() # Set the Paragraph styles in the Table of Contents toc.levelStyles = [heading1_style, heading2_style] story.append(toc) story.append(PageBreak()) ipsum = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.''' story.append(Paragraph('Heading #1', heading1_style)) story.append(Paragraph(ipsum, ParagraphStyle('body'))) story.append(Paragraph('Sub-heading #1', heading2_style)) story.append(Paragraph(ipsum, ParagraphStyle('body'))) story.append(PageBreak()) story.append(Paragraph('Sub-heading #2', heading2_style)) story.append(Paragraph(ipsum, ParagraphStyle('body'))) story.append(Paragraph('Heading #2', heading1_style)) doc = MyDocTemplate('toc.pdf') doc.multiBuild(story)
toc = TableOfContents() PS = ParagraphStyle toc.levelStyles = [ PS(fontName='Times-Bold', fontSize=14, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=16), PS(fontSize=12, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=0, leading=12), PS(fontSize=10, name='TOCHeading3', leftIndent=60, firstLineIndent=-20, spaceBefore=0, leading=12), PS(fontSize=10, name='TOCHeading4', leftIndent=100, firstLineIndent=-20, spaceBefore=0, leading=12), ] getStory().append(toc)
toc = TableOfContents() toc.dotsMinLevel = 0 toc.levelStyles = [ ParagraphStyle( fontName='Times-Bold', fontSize=12, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=6 ), ParagraphStyle( fontSize=10, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=2, leading=6 ), ParagraphStyle( fontSize=10, name='TOCHeading3', leftIndent=60, firstLineIndent=-20, spaceBefore=2, leading=6 ), ] Story.append(toc)
if __name__ == '__main__': doc = WikiDocTemplate("manual.pdf", leftMargin= 0.5*inch, rightMargin= 0.5*inch, topMargin= 0.5*inch, bottomMargin= 0.25*inch) story = [] # Title Page story.append(Spacer(0, 3.5*inch)) story.append(Paragraph(TITLE, styles['Title'])) story.append(PageBreak()) # Table of Contents toc = TableOfContents() toc.levelStyles = [styles['Normal']] * 6 story.append(toc) story.append(PageBreak()) parser = ContentParser(story) html = urllib2.urlopen(ROOT + "/knowledgebase").read().decode('utf8') parser.feed(html) parser.close() # crawl_page("/knowledgebase/articles/171592-how-to-print-your-tracks", story) print story print "Building PDF..." # Build PDF
firstLineIndent=-20, spaceBefore=0, leading=12) h3 = PS(fontSize=10, name='Heading3', leftIndent=60, firstLineIndent=-20, spaceBefore=0, leading=10) h4 = PS(fontSize=10, name='Heading4', leftIndent=100, firstLineIndent=-20, spaceBefore=0, leading=8) toc.levelStyles = [h1, h2, h3, h4] styles.add(PS(name='Justify', alignment=TA_JUSTIFY)) u = inch / 10.0 divide_string_threshold = 12 table_font_size = 8 text_font_size = 10 # Functions def title_page(canvas, doc): canvas.saveState() add_title_header(canvas) add_title_title(canvas) add_title_footer(canvas)
def log_go(self): story = list() # 报告内容存储结构 story.append(PageBreak()) # 目录 toc = TableOfContents() toc.dotsMinLevel = 0 toc.levelStyles = [H1, H2, H3] story.append(Paragraph('目录', toc1)) story.append(toc) # 分页 story.append(PageBreak()) add_title(story, '1 前言', h1) add_title(story, '1.1 报告阅读说明', h2) story.append( Paragraph( '本报告是对操作日志及系统日志的统计。操作日志主要内容包括操作用户ip地址top5,用户操作情况统计,' '以及用户操作日志随时间分布趋势。', body)) story.append( Paragraph('系统日志主要内容包括系统日志分布情况,系统警告日志数量趋势分布,' '以及系统日志总数随时间分布趋势。', body)) story.append(Paragraph('北京天地和兴科技有限公司感谢您对我们的信任和支持。现将设备运行日志报告呈上。', body)) if self.report_method in [1, 2, 3]: add_title(story, '1.2 周期性报表', h2) else: add_title(story, '1.2 自定义报表', h2) self.base_info_table(story) story.append(PageBreak()) story.append(Paragraph('2 日志概述', h1)) add_title(story, '2.1 操作日志概述', h2) add_title(story, '2.1.1 操作用户ip地址top5', h3) self.login_figure(story) add_title(story, '2.1.2 用户操作分布情况', h3) self.oper_figure(story) story.append(PageBreak()) add_title(story, '2.1.3 用户操作日志趋势分布', h3) self.oper_log_time(story) story.append(PageBreak()) add_title(story, '2.2 系统日志概述', h2) add_title(story, '2.2.1 系统日志分布情况', h3) self.sys_figure(story) add_title(story, '2.2.2 系统警告日志趋势分布', h3) self.alarm_log_time(story) story.append(PageBreak()) add_title(story, '2.2.3 系统日志趋势分布', h3) self.sys_log_time(story) story.append(PageBreak()) # about_us_3(story) try: doc = MyDocTemplate(path + '/pdf_tmp/log_report.pdf') logger.info( "====================enter log report multiBuild.............") doc.multiBuild(story, onFirstPage=firstPages, onLaterPages=laterPages) os.system("rm -rf " + path + "/tmp/") os.system("mv " + path + "/pdf_tmp/log_report.pdf " + "/data/report/log/") except: logger.error("MyDocTemplate build error.") logger.error(traceback.format_exc())
import reportlab title("ReportLab PDF Library") title("User Guide") centred('ReportLab Version ' + reportlab.Version) centred(datetime.now().strftime('Document generated on %Y/%m/%d %H:%M:%S %Z')) nextTemplate("TOC") headingTOC() toc = TableOfContents() PS = ParagraphStyle toc.levelStyles = [ PS(fontName='Times-Bold', fontSize=14, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=16), PS(fontSize=12, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=0, leading=12), PS(fontSize=10, name='TOCHeading3', leftIndent=60, firstLineIndent=-20, spaceBefore=0, leading=12), PS(fontSize=10, name='TOCHeading4', leftIndent=100, firstLineIndent=-20, spaceBefore=0, leading=12), ] getStory().append(toc) nextTemplate("Normal") ######################################################################## # # Chapter 1 # ######################################################################## heading1("Introduction")
def generateCustomSiteReport(self, pk, base_url, fs_ids): self.base_url = base_url # Our container for 'Flowable' objects elements = [] toc = TableOfContents() toc.levelStyles = [ PS(fontName='arialuni', fontSize=14, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=10), PS(fontName='arialuni', fontSize=12, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), PS(fontName='arialuni', ontSize=10, name='TOCHeading3', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), ] elements.append(Paragraph('Custom Responses Report for Site', self.centered)) elements.append(PageBreak()) elements.append(Paragraph('Table of contents', self.centered)) elements.append(toc) elements.append(PageBreak()) # A large collection of style sheets pre-made for us styles = getSampleStyleSheet() styles.add(ParagraphStyle(name='centered', alignment=TA_CENTER)) site = Site.objects.select_related('project').get(pk=pk) self.project_name = site.project.name self.project_logo = site.project.logo.url elements.append(Paragraph(site.name, self.h1)) elements.append(Paragraph(site.identifier, styles['Normal'])) if site.address: elements.append(Paragraph(site.address, styles['Normal'])) if site.phone: elements.append(Paragraph(site.phone, styles['Normal'])) if site.region: elements.append(Paragraph(site.region.name, styles['Normal'])) elements.append(PageBreak()) elements.append(Paragraph('Responses', self.h2)) forms = FieldSightXF.objects.select_related('xf').filter(pk__in=fs_ids, is_survey=False).prefetch_related(Prefetch('site_form_instances', queryset=FInstance.objects.select_related('instance'))).order_by('-is_staged', 'is_scheduled') if not forms: elements.append(Paragraph("No Any Responses Yet.", styles['Heading5'])) #a=FieldSightXF.objects.select_related('xf').filter(site_id=291).prefetch_related(Prefetch('site_form_instances', queryset=FInstance.objects.select_related('instance'))) styNormal = styleSheet['Normal'] styBackground = ParagraphStyle('background', parent=styNormal, backColor=colors.white) for form in forms: elements.append(Spacer(0,10)) elements.append(Paragraph(form.xf.title, self.h3)) elements.append(Paragraph(form.form_type() + " Form", styles['Heading4'])) if form.stage: if form.stage.stage: elements.append(Paragraph("Stage Id: " + str(form.stage.stage.order), styles['Heading5'])) elements.append(Paragraph("Sub Stage Id: " + str(form.stage.order), styles['Heading5'])) else: elements.append(Paragraph("Stage Id: " + str(form.stage.order), styles['Heading5'])) json_question = form.xf.json form_user_name = form.xf.user.username self.media_folder = form_user_name #cursor = get_instaces_for_site_individual_form(form.id) sub_count = 0 if form.site_form_instances.all(): for instance in form.site_form_instances.all(): if instance.form_status == 0: form_status = "Pending" elif instance.form_status == 1: form_status = "Rejected" elif instance.form_status == 2: form_status = "Flagged" elif instance.form_status == 3: form_status = "Approved" sub_count += 1 elements.append(Spacer(0,10)) elements.append(Paragraph("Submision "+ str(sub_count), styles['Heading4'])) elements.append(Paragraph("Status : "+form_status, styles['Normal'])) elements.append(Paragraph("Submitted By:"+instance.submitted_by.username, styles['Normal'])) elements.append(Paragraph("Submitted Date:"+str(instance.date), styles['Normal'])) elements.append(Spacer(0,10)) self.data = [] self.main_answer = instance.instance.json question = json.loads(json_question) self.parse_individual_questions(question['children']) t1 = Table(self.data, colWidths=(60*mm, None)) t1.setStyle(self.ts1) elements.append(t1) elements.append(Spacer(0,10)) else: elements.append(Paragraph("No Submisions Yet. ", styles['Heading5'])) elements.append(Spacer(0,10)) self.doc.multiBuild(elements, onLaterPages=self._header_footer)
def print_users(self, pk, base_url): centered = PS(name='centered', fontSize=14, leading=16, alignment=1, spaceAfter=20, fontName='Helvetica-Bold') h1 = PS( name='Heading1', fontSize=16, leading=16, fontName='Helvetica-Bold', spaceAfter=20, ) h2 = PS(name='Heading2', fontSize=14, leading=14, fontName='Helvetica-Bold', spaceAfter=20) h3 = PS( name='Heading3', fontSize=12, leading=12, fontName='Helvetica-BoldOblique', spaceAfter=20, ) self.base_url = base_url buffer = self.buffer doc = MyDocTemplate(buffer, rightMargin=72, leftMargin=72, topMargin=72, bottomMargin=72, pagesize=self.pagesize) # Our container for 'Flowable' objects elements = [] toc = TableOfContents() toc.levelStyles = [ PS(fontName='Helvetica-Bold', fontSize=14, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=10), PS(fontName='Helvetica', fontSize=12, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), PS(fontName='Helvetica', ontSize=10, name='TOCHeading3', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), ] elements.append(Paragraph('Responses Report for Site', centered)) elements.append(PageBreak()) elements.append(Paragraph('Table of contents', centered)) elements.append(toc) elements.append(PageBreak()) # A large collection of style sheets pre-made for us styles = getSampleStyleSheet() styles.add(ParagraphStyle(name='centered', alignment=TA_CENTER)) site = Site.objects.select_related('project').get(pk=pk) self.project_name = site.project.name self.project_logo = site.project.logo.url elements.append(Paragraph(site.name, h1)) elements.append(Paragraph(site.identifier, styles['Normal'])) if site.address: elements.append(Paragraph(site.address, styles['Normal'])) if site.phone: elements.append(Paragraph(site.phone, styles['Normal'])) if site.region: elements.append(Paragraph(site.region.name, styles['Normal'])) elements.append(PageBreak()) elements.append(Paragraph('Responses', h2)) forms = FieldSightXF.objects.select_related('xf').filter( site_id=pk, is_survey=False).prefetch_related( Prefetch('site_form_instances', queryset=FInstance.objects.select_related( 'instance'))).order_by('-is_staged', 'is_scheduled') if not forms: elements.append( Paragraph("No Any Responses Yet.", styles['Heading5'])) #a=FieldSightXF.objects.select_related('xf').filter(site_id=291).prefetch_related(Prefetch('site_form_instances', queryset=FInstance.objects.select_related('instance'))) ts1 = TableStyle([ ('ALIGN', (0, 0), (-1, 0), 'RIGHT'), ('BACKGROUND', (0, 0), (-1, 0), colors.white), ('VALIGN', (0, 0), (-1, -1), 'TOP'), ('GRID', (0, 0), (-1, -1), 0.1, colors.lightgrey), ]) styNormal = styleSheet['Normal'] styBackground = ParagraphStyle('background', parent=styNormal, backColor=colors.white) for form in forms: elements.append(Spacer(0, 10)) elements.append(Paragraph(form.xf.title, h3)) elements.append( Paragraph(form.form_type() + " Form", styles['Heading4'])) if form.stage: if form.stage.stage: elements.append( Paragraph("Stage Id: " + str(form.stage.stage.order), styles['Heading5'])) elements.append( Paragraph("Sub Stage Id: " + str(form.stage.order), styles['Heading5'])) else: elements.append( Paragraph("Stage Id: " + str(form.stage.order), styles['Heading5'])) json_question = form.xf.json form_user_name = form.xf.user.username self.media_folder = form_user_name #cursor = get_instaces_for_site_individual_form(form.id) sub_count = 0 if form.site_form_instances.all(): for instance in form.site_form_instances.all(): if instance.form_status == 0: form_status = "Pending" elif instance.form_status == 1: form_status = "Rejected" elif instance.form_status == 2: form_status = "Flagged" elif instance.form_status == 3: form_status = "Approved" sub_count += 1 elements.append(Spacer(0, 10)) elements.append( Paragraph("Submision " + str(sub_count), styles['Heading4'])) elements.append( Paragraph("Status : " + form_status, styles['Normal'])) elements.append( Paragraph( "Submitted By:" + instance.submitted_by.username, styles['Normal'])) elements.append( Paragraph("Submitted Date:" + str(instance.date), styles['Normal'])) elements.append(Spacer(0, 10)) self.data = [] self.main_answer = instance.instance.json question = json.loads(json_question) self.parse_individual_questions(question['children']) t1 = Table(self.data, colWidths=(60 * mm, None)) t1.setStyle(ts1) elements.append(t1) elements.append(Spacer(0, 10)) else: elements.append( Paragraph("No Submisions Yet. ", styles['Heading5'])) elements.append(Spacer(0, 10)) # elements.append(PageBreak()) # else: # elements.append(Paragraph("No Submissions Yet.", styles['Normal'])) # elements.append(Spacer(0,10)) # else: # elements.append(Paragraph("No Forms Yet.", styles['Normal'])) # elements.append(Spacer(0,10)) # self.parse_individual_questions(json_question['children']) doc.multiBuild(elements, onLaterPages=self._header_footer)
def initToc(cls): ret = TableOfContents() # For conciseness we use the same styles for headings and TOC entries ret.levelStyles = [cls.h1, cls.h2, cls.h3] return ret
def generateCustomSiteReport(self, pk, base_url, fs_ids, startdate, enddate, removeNullField): self.base_url = base_url self.removeNullField = removeNullField # Our container for 'Flowable' objects elements = [] toc = TableOfContents() toc.levelStyles = [ PS(fontName='arialuni', fontSize=12, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=10), PS(fontName='arialuni', fontSize=10, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), PS(fontName='arialuni', fontSize=9, name='TOCHeading3', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), ] elements.append( Paragraph('Custom Responses Report for Site', self.centered)) elements.append(PageBreak()) elements.append(Paragraph('Table of contents', self.centered)) elements.append(toc) elements.append(PageBreak()) # A large collection of style sheets pre-made for us styles = getSampleStyleSheet() styles.add(ParagraphStyle(name='centered', alignment=TA_CENTER)) site = Site.objects.select_related('project').get(pk=pk) self.project_name = site.project.name self.project_logo = site.project.logo.url elements.append(Paragraph(site.name, self.h1)) elements.append(Paragraph(site.identifier, styles['Normal'])) if site.address: elements.append(Paragraph(site.address, styles['Normal'])) if site.phone: elements.append(Paragraph(site.phone, styles['Normal'])) if site.region: elements.append(Paragraph(site.region.name, styles['Normal'])) elements.append(Spacer(0, 10)) elements.append(Paragraph("Site Information", styles['Normal'])) metas = generateSiteMetaAttribs(pk) styBackground = ParagraphStyle('background', parent=self.bodystyle, backColor=colors.white) meta_data = [] if metas: for meta in metas: row = [ Paragraph(str(meta['question_text']), styBackground), Paragraph(str(meta['answer']), styBackground) ] meta_data.append(row) metat1 = Table(meta_data, colWidths=(60 * mm, None)) metat1.setStyle(self.ts1) elements.append(metat1) elements.append(PageBreak()) elements.append(Paragraph('Responses', self.h2)) split_startdate = startdate.split('-') split_enddate = enddate.split('-') new_startdate = date(int(split_startdate[0]), int(split_startdate[1]), int(split_startdate[2])) end = date(int(split_enddate[0]), int(split_enddate[1]), int(split_enddate[2])) new_enddate = end + datetime.timedelta(days=1) forms = FieldSightXF.objects.select_related('xf').filter( pk__in=fs_ids, is_survey=False, is_deleted=False ).prefetch_related( Prefetch( 'site_form_instances', queryset=FInstance.objects.select_related('instance').filter( date__range=[new_startdate, new_enddate])), Prefetch( 'project_form_instances', queryset=FInstance.objects.select_related('instance').filter( site_id=site.id, date__range=[new_startdate, new_enddate ]))).order_by('-is_staged', 'is_scheduled') if not forms: elements.append( Paragraph("No Any Responses Yet.", styles['Heading5'])) #a=FieldSightXF.objects.select_related('xf').filter(site_id=291).prefetch_related(Prefetch('site_form_instances', queryset=FInstance.objects.select_related('instance'))) styNormal = styleSheet['Normal'] styBackground = ParagraphStyle('background', parent=styNormal, backColor=colors.white) for form in forms: elements.append(Spacer(0, 10)) elements.append(Paragraph(form.xf.title, self.h3)) elements.append( Paragraph(form.form_type() + " Form", styles['Heading4'])) if form.stage: if form.stage.stage: elements.append( Paragraph("Stage Id: " + str(form.stage.stage.order), self.paragraphstyle)) elements.append( Paragraph("Sub Stage Id: " + str(form.stage.order), self.paragraphstyle)) else: elements.append( Paragraph("Stage Id: " + str(form.stage.order), self.paragraphstyle)) json_question = form.xf.json form_user_name = form.xf.user.username self.media_folder = form_user_name #cursor = get_instaces_for_site_individual_form(form.id) sub_count = 0 if not form.from_project and form.site_form_instances.all(): for instance in form.site_form_instances.all(): new_elements = self.append_answers(json_question, instance, sub_count) elements += new_elements elif form.project_form_instances.all(): for instance in form.project_form_instances.all(): new_elements = self.append_answers(json_question, instance, sub_count) elements += new_elements else: elements.append( Paragraph("No Submisions Yet. ", styles['Heading5'])) elements.append(Spacer(0, 10)) self.doc.multiBuild(elements, onLaterPages=self._header_footer)
def generateFullReport(self, pk, base_url): self.base_url = base_url # Our container for 'Flowable' objects elements = [] toc = TableOfContents() toc.levelStyles = [ PS(fontName='arialuni', fontSize=12, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=10), PS(fontName='arialuni', fontSize=10, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), PS(fontName='arialuni', fontSize=9, name='TOCHeading3', leftIndent=40, firstLineIndent=-20, spaceBefore=3, leading=10), ] elements.append(Paragraph('Responses Report for Site', self.centered)) elements.append(PageBreak()) elements.append(Paragraph('Table of contents', self.centered)) elements.append(toc) elements.append(PageBreak()) # A large collection of style sheets pre-made for us styles = getSampleStyleSheet() styles.add(ParagraphStyle(name='centered', alignment=TA_CENTER)) site = Site.objects.select_related('project').get(pk=pk) self.project_name = site.project.name self.project_logo = site.project.logo.url elements.append(Paragraph(site.name, self.h1)) elements.append(Paragraph(site.identifier, styles['Normal'])) if site.address: elements.append(Paragraph(site.address, styles['Normal'])) if site.phone: elements.append(Paragraph(site.phone, styles['Normal'])) if site.region: elements.append(Paragraph(site.region.name, styles['Normal'])) elements.append(PageBreak()) elements.append(Paragraph('Responses', self.h2)) forms = FieldSightXF.objects.select_related('xf').filter( is_survey=False, is_deleted=False).filter( Q(site_id=site.id, from_project=False) | Q(project_id=site.project_id)).prefetch_related( Prefetch( 'site_form_instances', queryset=FInstance.objects.select_related('instance')), Prefetch( 'project_form_instances', queryset=FInstance.objects.select_related( 'instance').filter(site_id=site.id))).order_by( '-is_staged', 'is_scheduled') if not forms: elements.append( Paragraph("No Any Responses Yet.", styles['Heading5'])) #a=FieldSightXF.objects.select_related('xf').filter(site_id=291).prefetch_related(Prefetch('site_form_instances', queryset=FInstance.objects.select_related('instance'))) styNormal = styleSheet['Normal'] styBackground = ParagraphStyle('background', parent=styNormal, backColor=colors.white) for form in forms: elements.append(Spacer(0, 10)) elements.append(Paragraph(form.xf.title, self.h3)) elements.append( Paragraph(form.form_type() + " Form", styles['Heading4'])) if form.stage: if form.stage.stage: elements.append( Paragraph("Stage Id: " + str(form.stage.stage.order), self.paragraphstyle)) elements.append( Paragraph("Sub Stage Id: " + str(form.stage.order), self.paragraphstyle)) else: elements.append( Paragraph("Stage Id: " + str(form.stage.order), self.paragraphstyle)) json_question = form.xf.json form_user_name = form.xf.user.username self.media_folder = form_user_name #cursor = get_instaces_for_site_individual_form(form.id) sub_count = 0 if not form.from_project and form.site_form_instances.all(): for instance in form.site_form_instances.all(): self.append_answers(json_question, instance, sub_count) elif form.project_form_instances.all(): for instance in form.project_form_instances.all(): self.append_answers(json_question, instance, sub_count) else: elements.append( Paragraph("No Submisions Yet. ", styles['Heading5'])) elements.append(Spacer(0, 10)) self.doc.multiBuild(elements, onLaterPages=self._header_footer)
if flowable.__class__.__name__ == 'Paragraph': text = flowable.getPlainText() style = flowable.style.name if style == 'Heading1': self.notify('TOCEntry', (0, text, self.page)) if style == 'Heading2': self.notify('TOCEntry', (1, text, self.page)) h1 = PS(name = 'Heading1', fontSize = 14, leading = 16) h2 = PS(name = 'Heading2', fontSize = 12, leading = 14, leftIndent = delta) # story = [] toc = TableOfContents() # For conciseness we use the same styles for headings and TOC entries toc.levelStyles = [h1, h2] story.append(toc) story.append(PageBreak()) story.append(Paragraph('First heading', h1)) story.append(Paragraph('Text in first heading', PS('body'))) story.append(Paragraph('First sub heading', h2)) story.append(Paragraph('Text in first sub heading', PS('body'))) story.append(PageBreak()) story.append(Paragraph('Second sub heading', h2)) story.append(Paragraph('Text in second sub heading', PS('body'))) story.append(Paragraph('Last heading', h1)) doc = MyDocTemplate('mintoc.pdf') doc.multiBuild(story)
s_normal = styles['Normal'] s_right = ParagraphStyle(name='Right', parent=styles['Normal'], alignment=TA_RIGHT) s_center = ParagraphStyle(name='Center', parent=styles['Normal'], alignment=TA_CENTER) s_h1 = styles['Heading1'] s_h1_center = styles['Heading1'] s_h1_center.alignment = TA_CENTER s_h1n = ParagraphStyle(name='Heading1n', parent=styles['Normal'], fontSize=18, leading=22, spaceAfter=6, alignment=TA_CENTER) s_h1_toc = ParagraphStyle(name='Heading1toc', parent=styles['Heading1'], fontName='Helvetica', fontSize=16, leading=22, spaceBefore=4, spaceAfter=6, alignment=TA_LEFT) s_h2_toc = ParagraphStyle(name='Heading2toc', parent=styles['Heading2'], fontName='Helvetica', fontSize=13, leading=22, spaceBefore=2, spaceAfter=4, alignment=TA_LEFT) s_h2 = styles['Heading2'] s_code = styles['Code'] doc = None story = [] toc = TableOfContents() toc.levelStyles = [s_h1_toc, s_h2_toc] global_alignment_generated = False local_alignment_generated = False def add_page_number(canvas, _): canvas.saveState() canvas.setFont('Helvetica', 9) text = "Page %s" % canvas.getPageNumber() canvas.drawRightString(A4[0] - 0.4 * inch, 0.25 * inch, text) canvas.restoreState() def generate_splitline(width, height, color_a=chartreuse, color_b=coral): left_x = 0
frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal', showBoundary=0) # First page Elements.append(Paragraph("", styles['Normal'])) Elements.append(NextPageTemplate('OneCol')) Elements.append(PageBreak()) title(Elements, "Table of contents") toc = TableOfContents() # For conciseness we use the same styles for headings and TOC entries toc.levelStyles = [h1, h2] Elements.append(toc) Elements.append(PageBreak()) # Retrospective ( to keep ) title(Elements, "Retrospective") Elements.append(retroToKeep(getRetroToKeep())) Elements.append(PageBreak()) # Retrospective ( to improve and actions ) title(Elements, "Retrospective") Elements.append(retroToImproveAndActions(getRetroToImproveAndActions())) Elements.append(PageBreak()) # Review title(Elements, "Review")
Paragraph("<font size=12>Table of Contents</font>", styles["Normal"])) Story.append(Spacer(1, 6)) toc = TableOfContents() toc.dotsMinLevel = 0 toc.levelStyles = [ ParagraphStyle(fontName='Times-Bold', fontSize=12, name='TOCHeading1', leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=6), ParagraphStyle(fontSize=10, name='TOCHeading2', leftIndent=40, firstLineIndent=-20, spaceBefore=2, leading=6), ParagraphStyle(fontSize=10, name='TOCHeading3', leftIndent=60, firstLineIndent=-20, spaceBefore=2, leading=6), ] Story.append(toc) Story.append(PageBreak()) # ----------- Acquire the XML tree from the input file ----------------------------------------------