A Django app to generate pdfs from templates
Project description
Attention
This is a fork of the https://github.com/xhtml2pdf/django-xhtml2pdf project.
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.
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 resources appear in the pdf.
This release (0.0.7) supports Django 2.0, and Python 3.6.
NOTE:
While this project is being maintained on a limited basis for legacy projects, we recommend strongly that new projects consider using WeasyPrint <https://weasyprint.org>.
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 the 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lanshark-django-xhtml2pdf-0.0.7.tar.gz
.
File metadata
- Download URL: lanshark-django-xhtml2pdf-0.0.7.tar.gz
- Upload date:
- Size: 45.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3954fc1bb454aef1b4430d9dbbdb71476e8ea17aa7f0c41faf6cf7405ec7dd15 |
|
MD5 | 6220bbad4c80a5a316132bad4c71c91c |
|
BLAKE2b-256 | 96906b70c4cbd0d19aaacad91d3f6fc94bfeb33840f8617b8c1bd9169d7c14bc |
Provenance
File details
Details for the file lanshark_django_xhtml2pdf-0.0.7-py2.py3-none-any.whl
.
File metadata
- Download URL: lanshark_django_xhtml2pdf-0.0.7-py2.py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d4a3bb1a2286bb4fc5d79f3fece4d89d5e2064dff663d53982c988afe4a67cb |
|
MD5 | e0f6d9242610ceecacc591b8dcdd6923 |
|
BLAKE2b-256 | 644edbf069c25119c1019ebbc564ebd8afef1c0cca970722b2946987a0f76b9f |