gpt4 book ai didi

python - LayoutError at/invoice/Flowable with cell(0,0)

转载 作者:行者123 更新时间:2023-12-04 08:10:19 25 4
gpt4 key购买 nike

我正在尝试在 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 无法拆分大于可用空间的表格单元格。为了解决这个问题,您可以定义在这种情况下应该发生什么。 -pdf-keep-in-frame-mode可以是以下之一:“error”, “overflow”, “shrink”, “truncate”哪里“shrink”是默认值。

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

关于python - LayoutError at/invoice/Flowable <PmlTable@0x1D09C899130 7 rows x 5 cols(tallest row 841)> with cell(0,0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66005026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com