Skip to main content

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')

Metadata

Release files for django-xhtml2pdf 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-xhtml2pdf 0.0.4
File Size Uploaded
django-xhtml2pdf-0.0.4.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-xhtml2pdf 0.0.4
File Interpreter ABI Platform
django_xhtml2pdf-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / django-xhtml2pdf-0.0.4.tar.gz

Download URL django-xhtml2pdf-0.0.4.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e91f4ea6033fb0eb9ae3869fe764df3c756c22897b526587aef008fb04d69871
BLAKE2b-256 checksum
How to use checksums
11966828e583a56884bc5661a46afcbf9f67b5badb9b4fd55277d843c7d358d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_xhtml2pdf-0.0.4-py3-none-any.whl

Download URL django_xhtml2pdf-0.0.4-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84595fd7f242efffc1682eaf6646f237cb4823cda14e81b9cd642f6c790edd4e
BLAKE2b-256 checksum
How to use checksums
08ff92fc2d8e6e8bbd93237cc57c3a25ddea8ff016de31f5e488f1b2dfd29f46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

0.0.1.dev0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page