Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A Django app to generate pdfs from templates

Project description


This project is wrapper code between the django project and the xhtml2pdf project, both have a few maintaining so maybe are not ideal for your project.

Please get in touch if you would like to take over maintainership.

What it does is simply allow people to create xhtml2pdf templates using all the cool django things like STATIC_URL etc.. (like one would for a webpage template), and the utils function makes all the images and ressources appear in the pdf.


Simply do the following:

from django_xhtml2pdf.utils import generate_pdf

def myview(response):
    resp = HttpResponse(content_type='application/pdf')
    result = generate_pdf('my_template.html', file_object=resp)
    return result

Class-based views

You can use the provided PdfMixin with any view that subclasses TemplateView, example:

from django.views.generic.detail import DetailView
from django_xhtml2pdf.views import PdfMixin
from .models import Product

class ProductPdfView(PdfMixin, DetailView):
    model = Product
    template_name = "product_pdf.html"

It will output the rendered content of the view in pdf.


Simply do the following:

from django_xhtml2pdf.utils import pdf_decorator

def myview(request):
    return render(request, 'mytemplate.html')

Change de pdf file name:

from django_xhtml2pdf.utils import pdf_decorator

def myview(request):
    return render(request, 'mytemplate.html')

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-xhtml2pdf, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size django_xhtml2pdf-0.0.4-py3-none-any.whl (6.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-xhtml2pdf-0.0.4.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page