A Django app to generate pdfs from templates
Project description
Attention
This is a fork of the https://gitlab.com/lansharkconsulting/django/lanshark-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.5) 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
Hashes for lanshark-django-xhtml2pdf-0.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce7bb2973de23b569e89adf6f4ab03a562c2bcc2255b3fb31cb48c3f7faf3789 |
|
MD5 | ae4d103029bff703ac8ec52da7ff5822 |
|
BLAKE2b-256 | c43184451ba8235d59a0715f3a87bc445990aa6a4df70f8631f0bed456ec9a69 |
Hashes for lanshark_django_xhtml2pdf-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7b5dc583d57dce415a7fd119bf3b250521cbe68fb4e95915f3125665bf8cc8b |
|
MD5 | e8b2b250789b2bb5ad07635ade675b07 |
|
BLAKE2b-256 | 3a22e61d27397f1bd4a5632d2677212d803e34634008539df540718fa4407919 |