Question

I'm trying to build a view which would render itself to PDF. Each time I accessed the view, I had some random issues with the structure of rendered document / table. Tracking the error, I've came down to rendering completely static html code, and found out, that - each request, the resulting document size is different.

    template = get_template(self.get_report_template_name())
    html = template.render(Context({}))
    strobj = StringIO.StringIO()
    pisa.CreatePDF(html.encode("UTF-8"), strobj, encoding='UTF-8')
    return HttpResponse('len: %d' % strobj.len);

as you can see, each time the very same template is rendered, with empty context, to make sure nothing changes. anyway, the template doesn't use django templating language at all

the above code returns a bit different result each time I refresh the page

len: 2573, len: 2595 len: 2234, len: 2601, len: 2244, len: 2632,

etc ... (some of the values are repeated multiple time).

when saved & displayed these documents - they contains "broken" page structure, like incorrectly displayed table cell or something. Only one of these looks correct.

Any suggestions where to find the problem?

Was it helpful?

Solution

I've been through the same problem. Tried to fix it for hours... The only solution I've found was to downgrade xhtml2pdf to version 0.0.4.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top