【问题标题】:Django: Increase the value in reportlab for drawstringDjango:在reportlab中增加拉绳的值
【发布时间】:2012-09-20 08:23:23
【问题描述】:

我正在使用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

【问题讨论】:

    标签: django django-views reportlab


    【解决方案1】:

    您可能希望将画布的设置和保存移出循环,因此您最终会使用 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()
    

    【讨论】:

    • 感谢您的回复,但我只得到一个用户相同的输出。我没有得到不同的完整名单。
    • 您确定您有多个 Child_detail 记录吗?
    猜你喜欢
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多