报告实验室目录

2024-09-28 03:19:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在reportlab中创建这种类型的目录: enter image description here

目前,我正在使用reportlab TableOfContent类,它正在创建类似以下内容的输出: enter image description here

这对我来说没关系,但当我尝试使用addEntry()方法添加条目时,它什么也不做,下面是我的代码:

def table_of_content(self):
        toc = TableOfContents()
        PS = ParagraphStyle

        
        #*************************#

        #***Table of Contents***#
        self.story.append(Paragraph('<b>Table of Contents</b>', centered))
        toc.levelStyles = [
                            PS(fontName=FONT_NAME, fontSize=14, name='TOCHeading1',
                            leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=16),
                            PS(fontSize=12, name='TOCHeading2', fontName=FONT_NAME,
                            leftIndent=40, firstLineIndent=-20, spaceBefore=0, leading=12),
                            PS(fontSize=10, name='TOCHeading3', fontName=FONT_NAME,
                            leftIndent=60, firstLineIndent=-20, spaceBefore=0, leading=12),
                            PS(fontSize=10, name='TOCHeading4', fontName=FONT_NAME,
                            leftIndent=100, firstLineIndent=-20, spaceBefore=0, leading=12),
                            ]
        # self.story.append(para)

        toc.addEntry(0, "hammad", 1, 3)

        self.story.append(toc)

有人能帮我吗?我怎样才能在目录中添加条目?提前谢谢


Tags: ofnameselfpsfontstoryappendfontname

热门问题