/invoice/ Flowable <PmlTable@0x1D09C899130 7 rows x 5 cols(tallest row 841)> 处的 LayoutError with cell(0,0)

LayoutError at /invoice/ Flowable <PmlTable@0x1D09C899130 7 rows x 5 cols(tallest row 841)> with cell(0,0)

我正在尝试在 Django 中以 PDF 格式打印发票我使用 xhtml2pdf 转换 HTML 文档。到 PDF 但是当我尝试 运行 我的代码时它给了我这个错误:

LayoutError at /invoice/ Flowable <PmlTable@0x1D09C899130 7 rows x 5 cols(tallest row 841)> with cell(0,0) containing '<PmlKeepInFrame at 0x1d09b77d670> size=x'(538.5826771653543 x 5893.228346456693), tallest cell 841.9 points, too large on page 2 in frame 'body'(538.5826771653543 x 785.19685039370

这是我的 views.py

from django.http import HttpResponse
from django.views.generic import View
from booking.utils import render_to_pdf
from django.template.loader import get_template

class GeneratePDF(View):
    def get(self, request, *args, **kwargs):
        template = get_template('invoice.html')
        context = {
            "invoice_id": 1234,
            "customer_name": "John Cooper",
            "amount": 1399.99,
            "today": "Today",
        }
        html = template.render(context)
        pdf = render_to_pdf('invoice.html', context)
        if pdf:
            response = HttpResponse(pdf, content_type='application/pdf')
            filename = "Invoice_%s.pdf" %("12341231")
            content = "inline; filename='%s'" %(filename)
            download = request.GET.get("download")
            if download:
                content = "attachment; filename='%s'" %(filename)
            response['Content-Disposition'] = content
            return response
        return HttpResponse("Not found")

这是我的 urls.py

from django.urls import path
from booking.views import GeneratePDF

app_name = 'booking'

urlpatterns = [
  path('invoice/', GeneratePDF.as_view(), name ="invoice"),
]

我得到了答案 xhtml2pdf 无法拆分大于可用 space 的 table 个单元格。
要解决此问题,您可以定义在这种情况下应该发生什么。
-pdf-keep-in-frame-mode 可以是以下之一:“error”, “overflow”, “shrink”, “truncate” 其中 “shrink” 是默认值。

table {    -pdf-keep-in-frame-mode: shrink;}

documentation link