Skip to main content

Django PDF rendering

Django PDF rendering, easily convert html responses to pdf responses

Latest Version Wheel License

Developed by William Otieno.

Overview

This app makes rendering PDF files in Django really easy. It can be used to create invoices, bills and other documents from simple HTML markup and CSS styles. You can even embed images and use custom fonts.

The library provides both Class-Based View that is almost a drop-in replacement for Django’s TemplateView as well as helper functions to render PDFs in the backend outside the request scope (i.e. using Celery workers).

Quickstart

  1. Include dj-easy-pdf, xhtml2pdf in your requirements.txt file. If you are on Python 3 you need to install the latest version of Reportlab and the beta version of xhtml2pdf:

    $ pip install dj-easy-pdf
  2. Add easy_pdf to INSTALLED_APPS.

  3. Create HTML template for PDF document and add a view that will render it:

    {% extends "easy_pdf/base.html" %}
    
    {% block content %}
        <div id="content">
            <h1>Hi there!</h1>
        </div>
    {% endblock %}
    from easy_pdf.views import PDFTemplateView
    
    class HelloPDFView(PDFTemplateView):
        template_name = 'hello.html'
  4. You can also use a mixin to output PDF from Django generic views:

    class PDFUserDetailView(PDFTemplateResponseMixin, DetailView):
        model = get_user_model()
        template_name = 'user_detail.html'
  5. If you’re using Function Based views then:

    from easy_pdf.rendering import render_to_pdf_response
    
    def pdf_output(request):
        context = {}
        return render_to_pdf_response(request, "output.html", context)

Documentation

The full documentation is at dj-easy-pdf.readthedocs.io.

Dependencies

dj-easy-pdf depends on:

  • django>=3.2

  • xhtml2pdf

  • reportlab

License

dj-easy-pdf is released under the MIT license.

Other Resources

Commercial Support

This app and many other help us build better software and focus on delivering quality projects faster. We would love to help you with your next project so get in touch by dropping an email at jimmywilliamotieno@gmail.com

Metadata

Release files for dj-easy-pdf 0.4.7

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

Source distribution (sdist)

Source distribution for dj-easy-pdf 0.4.7
File Size Uploaded
dj-easy-pdf-0.4.7.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-easy-pdf 0.4.7
File Interpreter ABI Platform
dj_easy_pdf-0.4.7-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 19.2 kB

Release files / dj-easy-pdf-0.4.7.tar.gz

Download URL dj-easy-pdf-0.4.7.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7a276eacb2351118e451d577791b3fba6df8fe5478ec7052cf76998976554744
BLAKE2b-256 checksum
How to use checksums
0454c2780c02ef7c4b90819fc83a4c9699668f0cb12778841ad2d6098e4b873a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / dj_easy_pdf-0.4.7-py2.py3-none-any.whl

Download URL dj_easy_pdf-0.4.7-py2.py3-none-any.whl
Size 9.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cc260ed553e52cf15504bc33532aa122267e120696897e0848c24ab8dc757fde
BLAKE2b-256 checksum
How to use checksums
a168d2826854ec0faf4debdc64c37a84adbd827badddff29af7ea51e537e311c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.4.7 This release

2 release files

0.4.6

2 release files

0.3.6

2 release files

0.2.4

2 release files

0.2.1

2 release files

0.0.0

2 release files

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