django form converter to PDF

168 views
Skip to first unread message

M Hashmi

unread,
Oct 3, 2016, 8:05:43 AM10/3/16
to django...@googlegroups.com
Hi,

I need some simple library to convert a simple quote form to PDF. I tried xhtml2pdf and few others but need really simple process to use but creating a fancy pdf.

If anyone knows please let me know.

Regards,
Mudassar

ludovic coues

unread,
Oct 3, 2016, 8:27:56 AM10/3/16
to django...@googlegroups.com
the xhtml2pdf doc point to weasyprint [1]. After a quick look at the
doc [2], it look like a simple way to generate pdf from html file.
If you already have a url on your django app rendering the quote, I
would use weasyprint like that:


from io import BytesIO
from django.http.response import HttpResponse
from django.urls import reverse
from weasyprint import HTML

def view(request):
pdf = BytesIO()
HTML(url=reverse("app:quote").write_pdf(pdf)
return HttpResponse(pdf.getvalue(), content_type="application/pdf")


I haven't tested the code, but It should work, assuming "app:quote"
resolve to an actual url :)

[1] http://weasyprint.org/
[2] http://weasyprint.readthedocs.io/en/latest/tutorial.html#as-a-python-library
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANoUts5Bz-bWq7vr%2BJtBOnDKj9EzkpnxYE5z2T9CV1TAN2Nr%2Bw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

M Hashmi

unread,
Oct 3, 2016, 8:37:04 AM10/3/16
to django...@googlegroups.com
You are a rockstar in the group man. Let me try it and I will let you know about the results. I didn't get a change to look at Weasy_print.

Regards,
Mudassar




--

Cordialement, Coues Ludovic
+336 148 743 42

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

06us...@gmail.com

unread,
Oct 3, 2016, 12:37:30 PM10/3/16
to Django users
Hello Mudassar,
I agree with Ludovic : you could try weasyprint. I am using it on my project and am very satisfied.

One hint : if I remember correctly, images on html page should be png in order for pdf to be generated by default.
jpg support package is optional. See documentation https://media.readthedocs.org/pdf/weasyprint/latest/weasyprint.pdf :

Optional: GDK-PixBuf 2

2 Without it, PNG and SVG are the only supported image format: JPEG, GIF and others are not available.


Cheers

Walt

unread,
Oct 3, 2016, 1:01:10 PM10/3/16
to Django users
You can also check out the Python wrapper for pdftk.


It allows you to take a pdf form and fill it dynamically and "flatten" it.

Aside from that, Weasyprint also works pretty well.


Walt

Ovnicraft

unread,
Oct 3, 2016, 2:04:47 PM10/3/16
to django...@googlegroups.com
On Mon, Oct 3, 2016 at 7:05 AM, M Hashmi <mhash...@gmail.com> wrote:
Hi,

I need some simple library to convert a simple quote form to PDF. I tried xhtml2pdf and few others but need really simple process to use but creating a fancy pdf.

I highly recommend you check http://wkhtmltopdf.org/ it works really good with html files.

There is a wrapper for Django https://github.com/incuna/django-wkhtmltopdf



 

If anyone knows please let me know.

Regards,
Mudassar

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANoUts5Bz-bWq7vr%2BJtBOnDKj9EzkpnxYE5z2T9CV1TAN2Nr%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages