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
File details
Details for the file drf-pdf-renderer-0.1.2.tar.gz
.
File metadata
- Download URL: drf-pdf-renderer-0.1.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb6ed492273f745efb15f62f4b28374821dba9d8fbb10a05e59314e06a31ac84 |
|
MD5 | 8320eeb93c93ac806ef174a36c4cb65f |
|
BLAKE2b-256 | f524293a1f6c93878a75c92393b854604c1e8a1ab31bae146c5a27d212e892da |