A simplistic/very extendable pdf renderer.
Project description
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}
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
drf-pdf-renderer-0.1.2.tar.gz
(8.1 kB
view hashes)