django generate pdf with tables and charts

1,495 views
Skip to first unread message

Jaimin Patel

unread,
Feb 10, 2013, 11:10:58 AM2/10/13
to django...@googlegroups.com
I am trying to generate pdf using django template, also need some support of javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it seems that it doesn't wait for Javascript. 

Can someone suggest good solution or example?

Peter of the Norse

unread,
Feb 13, 2013, 8:16:32 PM2/13/13
to django...@googlegroups.com
Django doesn’t run Javascript, that’s done in the browser. If you really want to have JS processing you’ll have to open a web browser and then print to PDF.

On Feb 10, 2013, at 9:10 AM, Jaimin Patel wrote:

> I am trying to generate pdf using django template, also need some support of javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it seems that it doesn't wait for Javascript.
>
> Can someone suggest good solution or example?
>

Peter of the Norse
Rahm...@Radio1190.org



Waitman Gobble

unread,
Feb 13, 2013, 10:28:34 PM2/13/13
to django...@googlegroups.com


On Feb 10, 2013 8:11 AM, "Jaimin Patel" <jaimi...@gmail.com> wrote:
>
> I am trying to generate pdf using django template, also need some support of javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it seems that it doesn't wait for Javascript. 
>
> Can someone suggest good solution or example?
>

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

You could send a request using Ajax, to a cgi program on the server, and include the URL. The program would pull the content and convert to pdf, then return the URL of the document. If the user has to be authenticated to view the content, then you would have to pass the authentication key to the CGI program. You may find something like html2pdf will do the conversion, there are free and non-free programs available.

Waitman Gobble
San Jose California USA

Ovnicraft

unread,
Feb 13, 2013, 10:45:40 PM2/13/13
to django...@googlegroups.com
On Sun, Feb 10, 2013 at 11:10 AM, Jaimin Patel <jaimi...@gmail.com> wrote:
I am trying to generate pdf using django template, also need some support of javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it seems that it doesn't wait for Javascript. 

Hello, can you explain us better what you means with *does not wait for JS* ? 
I understand you say: pdf is rendered w/o running JS code.

Regards, 

Can someone suggest good solution or example?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Cristian Salamea
@ovnicraft

Frank Bieniek

unread,
Feb 14, 2013, 7:27:23 AM2/14/13
to django...@googlegroups.com
Checkout happypdf.com
rest call to create your pdfs

Jaimin Patel

unread,
Feb 14, 2013, 9:45:38 AM2/14/13
to django...@googlegroups.com
Sure.

I had tried to render PDF with pisa,

    template = get_template(template_src)
    context = Context(context_dict)
    html  = template.render(context)
    result = StringIO.StringIO()

    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result, link_callback=fetch_resources)
    if not pdf.err:
        return HttpResponse(result.getvalue(), mimetype='application/pdf')
    return HttpResponse('Errors<pre>%s</pre>' % escape(html))

Also tried with wkhtmltopdf -

from wkhtmltopdf.views import PDFTemplateResponse
......
return PDFTemplateResponse(request, 'pdf/pdftemplate.html', {
            'pagesize':'A4',
           'user': results['user'],
           'question': results['question_obj'],
       })

In both cases it doesn't render the elements which I am populating with help of onload javascript function.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages