DRF PDF Renderer
A simplistic/very extendable pdf renderer.
If you use or like the project, click Star and Watch to generate metrics and i evaluate project continuity.
OBS
This project is a Beta version, however is used in production in a big project (with custom pdf template, and manually fields instead of automatic).
however, due to my low availability, updates may take some time.
but i will keep an eye on the PR.
Install:
pip install drf-pdf-renderer
Usage:
-
Add to your
INSTALLED_APPS, insettings.py:INSTALLED_APPS = [ ... 'drf_pdf_renderer', ... ] -
In your file:
from rest_framework.settings import api_settings from drf_pdf_renderer.renderer import PDFRendererPaginated class YourView(...) renderer_classes = (*api_settings.DEFAULT_RENDERER_CLASSES, PDFRendererPaginated) pdf_display_fields = (['id', 'Label for ID'], ) # used only in automatic field (caution: refactor planned in futures versions) pdf_display_fields = '' # contains two built-in templates ['pdf/list_landscape.html', 'pdf/list_portrait.html'] ... ... -
Mixin for paginated results
- if you have a pagination on DRF, but require a PDF with all registries, you can use this Mixin
from rest_framework.settings import api_settings from drf_pdf_renderer.mixin import PdfAllResultsMixin class YourView(PdfAllResultsMixin, ...) pdf_display_fields = (['id', 'Label for ID'], ) # used only in automatic field (caution: refactor planned in futures versions) pdf_display_fields = '' # contains two built-in templates ['pdf/list_landscape.html', 'pdf/list_portrait.html'] ... ...
Advanced
-
Custom PDF Template
-
Changing PDF title
# First way class YourView(...) pdf_title = 'My Title' # Second way class YourView(...) def pdf_get_title(self, data, context) return '' -
Changing PDF download name
# First way class YourView(...) pdf_filename = 'My Title' # Second way class YourView(...) def pdf_get_filename(self, pdf, data) return '' -
Custom data to render context
- By default `data`, `request`, `title` and `fields` will always be present (but can be rewrited) # Second way class YourView(...) def pdf_mount_context(data) return {'adm': True}
Metadata
Release files for drf-pdf-renderer 0.1.2
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 |
|---|---|---|---|---|
| drf-pdf-renderer-0.1.2.tar.gz | 8.1 kB | Without provenance | Details for drf-pdf-renderer-0.1.2.tar.gz |
Release files / drf-pdf-renderer-0.1.2.tar.gz
| Download URL | drf-pdf-renderer-0.1.2.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb6ed492273f745efb15f62f4b28374821dba9d8fbb10a05e59314e06a31ac84
|
|
BLAKE2b-256 checksum How to use checksums |
f524293a1f6c93878a75c92393b854604c1e8a1ab31bae146c5a27d212e892da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10
|
Security for drf-pdf-renderer 0.1.2
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.