A simple django app to generate PDF documents.
Installation
In your settings.py, add pdfutils to your INSTALLED_APPS.
(r’^reports/’, include(pdfutils.site.urls)), to your urls.py
Add pdfutils.autodiscover() to your urls.py
Create a report.py file in any installed django application.
Create your report(s)
Profit!
Note: If you are using buildout, don’t forget to put pdfutils in your eggs section or else the django-pdfutils dependencies wont be installed.
Example report
Reports are basically views with custom methods and properties.
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from pdfutils.reports import Report
from pdfutils.sites import site
class MyUserReport(Report):
title = _('Users')
template_name = 'myapp/reports/users-report.html'
slug = 'users-report'
orientation = 'portrait'
def get_users(self):
return User.objects.filter(is_staff=True)
def get_styles(self):
"""
It is possible to add or override style like so
"""
self.add_styles('myapp/css/users-report.css')
return super(AccountStatementReport, self).get_styles()
def filename(self):
"""
The filename can be generated dynamically and translated
"""
return _('Users-report-%(count)s.pdf') % {'count': self.get_users().count() }
def get_context_data(self):
"""
Context data is injected just like a normal view
"""
context = super(AccountStatementReport, self).get_context_data()
context['user_list'] = self.get_users()
return context
site.register(MyUserReport)
The slug should obviously be unique since it is used to build the report URL.
For example, with the default settings and URLs, the URL for report above would be /reports/users-report/.
Example template
<html>
<head>
{{ STYLES|safe }}
</head>
<body class="{% if landscape %}landscape{% else %}portrait{% endif %}">
<ul>
{% for user in user_list %}
<li>{{ user }}</li>
{% endif %}
</ul>
<a href="{% url 'pdfutils:your_report_slug' %}?format=html">Add ?format=html for easy template debug</a>
</body>
</html>
Some template variables are injected by default in reports:
title
slug
orientation
MEDIA_URL
STATIC_URL
STYLES
Overriding default CSS
Since the default CSS (base.css, portrait.css, landscape.css) are normal static files, they can be overrided from any other django app which has a pdfutils folder in their static folder.
Note: Be sure your applications are listed in the right order in INSTALLED_APPS !
Dependencies
django >=1.4, < 1.5.99
decorator == 3.4.0, <= 3.9.9
PIL == 1.1.7
reportlab == 2.5
html5lib == 0.90
httplib2 == 0.9
pyPdf == 1.13
xhtml2pdf == 0.0.4
django-xhtml2pdf == 0.0.3
Note: dependencies versions are specified in setup.py. The amount of time required to find the right combination of dependency versions is largely to blame for the creation of this project.
Metadata
Release files for PDFutils 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| PDFutils-1.1.3.tar.gz | 8.4 kB | Without provenance | Details for PDFutils-1.1.3.tar.gz |
Release files / PDFutils-1.1.3.tar.gz
| Download URL | PDFutils-1.1.3.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7cf4dfef2d15dd86b758a2c77a6737579531cf47548b9ba02e923838dadbc9f
|
|
BLAKE2b-256 checksum How to use checksums |
640a5291856751192d34c9ecc4ed4d072fd14c37f02aa6986c89e69fb5bee630
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for PDFutils 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.