0

我正在使用reportlab 生成pdf。在这里,我从数据库中检索配置文件。打印到数据库时,每个配置文件都应显示在下一页中。为此,我无法在增加页面坐标的同时打印该值。

def reportlab(request):

    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
    buffer = BytesIO()

    # Draw things on the PDF. Here's where the PDF generation happens.
    # See the ReportLab documentation for the full list of functionality.
    child = Child_detail.objects.all()
    for child1 in child:
        name = child1.name
        p = canvas.Canvas(buffer)
        p.drawString(500, 400, name)
        p.showPage()
        p.save()
    pdf = buffer.getvalue()
    buffer.close()
    response.write(pdf)
    return response
4

1 回答 1

0

您可能希望将画布的设置和保存移出循环,因此您最终使用了 Canvas 的单个实例

p = canvas.Canvas(buffer)
child = Child_detail.objects.all()
for child1 in child:
    name = child1.name
    p.drawString(500, 400, name)
    p.showPage()
p.save()
于 2012-09-20T08:37:04.467 回答