在为 repaortlab 布局错误创建 pdf 时

发布于 2025-01-09 09:26:41 字数 4977 浏览 1 评论 0原文

raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: 
Flowable <Table@0x7FA13491B898 1 rows x 1 cols(tallest row 900)> with cell(0,0) containing
'<Table@0x7FA1349110B8 1 rows x 1 cols(tallest row 894)> with cell(0,0) containing\n\'<Table@0x7FA1349894E0 1 rows x 1 cols(tallest row 24)> with cell(0,0) containing\\n"<Table@0x7FA134989438 1 rows x 1 cols(tallest row 18)> with cell(0,0) containing\\\\n\\\'Vulnerability ( Virustotal Domain Report )\\\'"\''(583.2755905511812 x 900), tallest cell 900.0 points,  too large on page 6 in frame 'normal'(583.2755905511812 x 794.8897637795277*) of template 'Later'

我为其制作了 PDF(A4) 尺寸并收到错误,而我在此处输入代码为其制作了 A3 问题已解决,我想要 A4 尺寸的解决方案。

def getToolsTables(data, tname):
    doc = SimpleDocTemplate(
        "somefilename.pdf",
        pagesize=A2,
        topMargin=25,
        bottomMargin=0,
    )
    main_header = []
    h_arr1 = []
    h_arr1.append(tname)
    main_header.append(h_arr1)
    mainHeader = Table(main_header, colWidths="*")

    finalTable = []

    main_table_header_Style = TableStyle(
        [
            ("BACKGROUND", (0, 0), (-1, 0), "#D3D3D3"),
            ("TEXTCOLOR", (0, 0), (-1, -1), colors.black),
            ("ALIGN", (0, 0), (-1, -1), "LEFT"),
            ("FONTSIZE", (0, 0), (-1, -1), 12),
            ("FONTNAME", (0, 0), (-1, -1), "Courier-Bold"),
            ("TOPPADDING", (0, 0), (-1, -1), 5),
            ("BOTTOMPADDING", (0, 0), (-1, -1), 7),
            ("LINEBELOW", (0, 0), (-1, 0), 1, colors.black),
        ]
    )

    tools_table_header_Style = TableStyle(
        [
            ("BACKGROUND", (0, 0), (-1, 0), "lightblue"),
            ("TEXTCOLOR", (0, 0), (-1, -1), colors.black),
            ("ALIGN", (0, 0), (-1, -1), "LEFT"),
            ("FONTSIZE", (0, 0), (-1, -1), 11),
            ("FONTNAME", (0, 0), (-1, -1), "Courier-Bold"),
        ]
    )

    tools_table_header_Style1 = TableStyle(
        [
            ("BACKGROUND", (0, 0), (-1, 0), "lightgreen"),
            ("TEXTCOLOR", (0, 0), (-1, -1), colors.black),
            ("ALIGN", (0, 0), (-1, -1), "CENTER"),
            ("FONTSIZE", (0, 0), (-1, -1), 11),
            ("FONTNAME", (0, 0), (-1, -1), "Courier-Bold"),
        ]
    )

    Style2 = TableStyle(
        [
            ("ALIGN", (0, 0), (-1, -1), "LEFT"),
            ("LEFTPADDING", (0, 0), (-1, -1), 0),
            ("RIGHTPADDING", (0, 0), (-1, -1), 0),
            ("BOTTOMPADDING", (0, 0), (-1, -1), -10),
        ]
    )

    Style3 = TableStyle(
        [
            ("VALIGN", (0, 0), (-1, -1), "TOP"),
            ("ALIGN", (0, 0), (-1, -1), "RIGHT"),
            ("LEFTPADDING", (0, 0), (-1, -1), 130),
            ("RIGHTPADDING", (0, 0), (-1, -1), 0),
            ("TOPPADDING", (0, 0), (-1, -1), 0),
        ]
    )

    Style4 = TableStyle([("VALIGN", (0, 0), (-1, -1), "TOP")])

    mainHeader.setStyle(
        main_table_header_Style
    )  # adding style to table main header
    finalTable.append(mainHeader)

    # Create Tools Array
    tools_header = []
    tools_body = []

    if type(data) == dict:
        all_table = []
        for key, value in data.items():
            temp = []
            temp_table = []
            temp.append(key)
            tool_table_header = Table([temp], colWidths="*")
            tool_table_header.setStyle(tools_table_header_Style)
            temp_table.append(tool_table_header)

            if key != "Builtwith":
                t_h = []
                t_b = []
                for k, v in value.items():
                    t_h.append(k)
                    t_b.append(v)

                t_body = []
                for index, item in enumerate(t_h):
                    if item != "status":
                        arr1 = []
                        arr2 = []
                        if type(t_b[index]) is list:
                            temp_txt = ""
                            for txt in t_b[index]:
                                temp_txt += txt + ",  "
                            arr1.append(item + ":")

                            text = t_b[index]
                            wraped_text = "\n".join(
                                wrap(str(temp_txt[:-3]), 60)
                            )  # 60 is line width
                            arr1.append(wraped_text)

                        else:
                            # MY CODE
                            arr2.append(arr1)
                            n_table = Table(arr2, [200, 370])
                            n_table.setStyle(Style4)
                            t_body.append(n_table)

                tool_header = Table([temp_table], colWidths="*")
                tool_body = Table([[t_body]], [200, 370])
                finalTable.append(
                    Table(
                        [[[tool_header, tool_body]]],
                        colWidths="*",
                    )
                )
raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: 
Flowable <Table@0x7FA13491B898 1 rows x 1 cols(tallest row 900)> with cell(0,0) containing
'<Table@0x7FA1349110B8 1 rows x 1 cols(tallest row 894)> with cell(0,0) containing\n\'<Table@0x7FA1349894E0 1 rows x 1 cols(tallest row 24)> with cell(0,0) containing\\n"<Table@0x7FA134989438 1 rows x 1 cols(tallest row 18)> with cell(0,0) containing\\\\n\\\'Vulnerability ( Virustotal Domain Report )\\\'"\''(583.2755905511812 x 900), tallest cell 900.0 points,  too large on page 6 in frame 'normal'(583.2755905511812 x 794.8897637795277*) of template 'Later'

I make a PDF(A4) size for it and got the error, while Ienter code here make A3 for it the problem is solved, i want the solution for A4 size.

def getToolsTables(data, tname):
    doc = SimpleDocTemplate(
        "somefilename.pdf",
        pagesize=A2,
        topMargin=25,
        bottomMargin=0,
    )
    main_header = []
    h_arr1 = []
    h_arr1.append(tname)
    main_header.append(h_arr1)
    mainHeader = Table(main_header, colWidths="*")

    finalTable = []

    main_table_header_Style = TableStyle(
        [
            ("BACKGROUND", (0, 0), (-1, 0), "#D3D3D3"),
            ("TEXTCOLOR", (0, 0), (-1, -1), colors.black),
            ("ALIGN", (0, 0), (-1, -1), "LEFT"),
            ("FONTSIZE", (0, 0), (-1, -1), 12),
            ("FONTNAME", (0, 0), (-1, -1), "Courier-Bold"),
            ("TOPPADDING", (0, 0), (-1, -1), 5),
            ("BOTTOMPADDING", (0, 0), (-1, -1), 7),
            ("LINEBELOW", (0, 0), (-1, 0), 1, colors.black),
        ]
    )

    tools_table_header_Style = TableStyle(
        [
            ("BACKGROUND", (0, 0), (-1, 0), "lightblue"),
            ("TEXTCOLOR", (0, 0), (-1, -1), colors.black),
            ("ALIGN", (0, 0), (-1, -1), "LEFT"),
            ("FONTSIZE", (0, 0), (-1, -1), 11),
            ("FONTNAME", (0, 0), (-1, -1), "Courier-Bold"),
        ]
    )

    tools_table_header_Style1 = TableStyle(
        [
            ("BACKGROUND", (0, 0), (-1, 0), "lightgreen"),
            ("TEXTCOLOR", (0, 0), (-1, -1), colors.black),
            ("ALIGN", (0, 0), (-1, -1), "CENTER"),
            ("FONTSIZE", (0, 0), (-1, -1), 11),
            ("FONTNAME", (0, 0), (-1, -1), "Courier-Bold"),
        ]
    )

    Style2 = TableStyle(
        [
            ("ALIGN", (0, 0), (-1, -1), "LEFT"),
            ("LEFTPADDING", (0, 0), (-1, -1), 0),
            ("RIGHTPADDING", (0, 0), (-1, -1), 0),
            ("BOTTOMPADDING", (0, 0), (-1, -1), -10),
        ]
    )

    Style3 = TableStyle(
        [
            ("VALIGN", (0, 0), (-1, -1), "TOP"),
            ("ALIGN", (0, 0), (-1, -1), "RIGHT"),
            ("LEFTPADDING", (0, 0), (-1, -1), 130),
            ("RIGHTPADDING", (0, 0), (-1, -1), 0),
            ("TOPPADDING", (0, 0), (-1, -1), 0),
        ]
    )

    Style4 = TableStyle([("VALIGN", (0, 0), (-1, -1), "TOP")])

    mainHeader.setStyle(
        main_table_header_Style
    )  # adding style to table main header
    finalTable.append(mainHeader)

    # Create Tools Array
    tools_header = []
    tools_body = []

    if type(data) == dict:
        all_table = []
        for key, value in data.items():
            temp = []
            temp_table = []
            temp.append(key)
            tool_table_header = Table([temp], colWidths="*")
            tool_table_header.setStyle(tools_table_header_Style)
            temp_table.append(tool_table_header)

            if key != "Builtwith":
                t_h = []
                t_b = []
                for k, v in value.items():
                    t_h.append(k)
                    t_b.append(v)

                t_body = []
                for index, item in enumerate(t_h):
                    if item != "status":
                        arr1 = []
                        arr2 = []
                        if type(t_b[index]) is list:
                            temp_txt = ""
                            for txt in t_b[index]:
                                temp_txt += txt + ",  "
                            arr1.append(item + ":")

                            text = t_b[index]
                            wraped_text = "\n".join(
                                wrap(str(temp_txt[:-3]), 60)
                            )  # 60 is line width
                            arr1.append(wraped_text)

                        else:
                            # MY CODE
                            arr2.append(arr1)
                            n_table = Table(arr2, [200, 370])
                            n_table.setStyle(Style4)
                            t_body.append(n_table)

                tool_header = Table([temp_table], colWidths="*")
                tool_body = Table([[t_body]], [200, 370])
                finalTable.append(
                    Table(
                        [[[tool_header, tool_body]]],
                        colWidths="*",
                    )
                )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2025-01-16 09:26:41

Table 类中使用 splitInRow 参数,以便它将拆分另一个页面上的数据,例如:

tool_body = Table([[t_body]], [200, 370], splitInRow=1)

Use splitInRow argument in the Table class so that it will split the data on the other page, for example:

tool_body = Table([[t_body]], [200, 370], splitInRow=1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文