Skip to main content

A django app to render django templates as PDF files.

Project description

Travis CI build status Codecov coverage report Version on PyPI Licence

django-renderpdf is a Django app to render django templates as PDF files.

Introduction

Rendering PDFs for web developers is generally pretty non-trivial, and there’s no common approach to doing this. django-renderpdf attempts to allow reusing all the known tools and skills when generating a PDF file in a Django app:

  • Use Django template files, which are internally rendered as HTML and them PDF files.
  • Use staticfiles app to include any CSS or image files.
  • Simply subclass a PDFView class which has an interface very similar to Django’s own built-in View classes.

Background

django-renderpdf actually started out as code on multiple of my own projects (including some public ones).

After some time, it became clear that I’d been copy-pasting PDF-related bits across different projects, and since co-workers expressed interest in this design (using the Django templating system to generate PDFs), it finally made sense to move this into a separate library.

Because of this, documentation is still a work in progress (the code far outdates this API being public), and while unit tests are lacking, this code has had ample field testing

Usage example

Sorry, no docs yet! Though PDFView’s methods has extensive docstrings you should check.

Here’s a usage code example for a view that generates some PDF labels for some shipments:

class LabelsView(LoginRequiredMixin, PDFView):
    template_name = 'my_app/labels.html'

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)

        context['shipments'] = models.Shipment.objects.filter(
            batch_id=kwargs['pk'],
        )

        return context

And in urls.py:

url(
    r'^/shipments/labels/(?P<pk>\d+)/$',
    views.LabelsView.as_view(),
    name='shipment_labels',
),

Licence

django-renderpdf is licensed under the ISC licence. See LICENCE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_renderpdf-1.0.0-py3-none-any.whl (8.2 kB) Copy SHA256 hash SHA256 Wheel py3 Dec 21, 2017
django-renderpdf-1.0.0.tar.gz (20.6 kB) Copy SHA256 hash SHA256 Source None Dec 21, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page