Why django library xhtml2pdf returning an error?

159 views Asked by At

I am using xhtml2pdf library in drf viewset to generate a pdf document from an html template that lists all records from a given model. Below is the action that I have defined inside my vieset

@action(detail=False)
def pdf(self, request, *args, **kwargs):
    import datetime
    filter = self.filter_queryset(Ledger.objects.values_list('name','groupid__name','panno', gstin'))
    pdf_obj = render_to_pdf('reports/report.html', {'data': filter})
    if pdf_obj:
        response = HttpResponse(pdf_obj, content_type='application/pdf')
        filename = 'Ledgers-' + str(datetime.date.today()) + '.pdf'
        content = "inline; filename=%s" % (filename)
        download = request.GET.get("download")
        if download:
            content = "attachment; filename=%s" % (filename)
        response['Content-Disposition'] = content
        return response

This results in ValueError exception with following message

<PmlTable@0x7F7C4304B390 2 rows x 0 cols>... must have at least a row and column

I am clueless what am I doing wrong here, Please advise.

0

There are 0 answers