Skip to main content

A Django app to generate pdfs from templates

Project description

Attention

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.

Usage

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.

Decorator

Simply do the following:

from django_xhtml2pdf.utils import pdf_decorator

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

Change de pdf file name:

from django_xhtml2pdf.utils import pdf_decorator

@pdf_decorator(pdfname='new_filename.pdf')
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.

Source Distribution

django-xhtml2pdf-0.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

django_xhtml2pdf-0.0.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file django-xhtml2pdf-0.0.4.tar.gz.

File metadata

File hashes

Hashes for django-xhtml2pdf-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e91f4ea6033fb0eb9ae3869fe764df3c756c22897b526587aef008fb04d69871
MD5 6590a953be251cdb0919b2b5b8db0769
BLAKE2b-256 11966828e583a56884bc5661a46afcbf9f67b5badb9b4fd55277d843c7d358d8

See more details on using hashes here.

File details

Details for the file django_xhtml2pdf-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_xhtml2pdf-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 84595fd7f242efffc1682eaf6646f237cb4823cda14e81b9cd642f6c790edd4e
MD5 126ebd28eb3053d45e7c8f89c0ad0540
BLAKE2b-256 08ff92fc2d8e6e8bbd93237cc57c3a25ddea8ff016de31f5e488f1b2dfd29f46

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page