Django Persian PDF is a set of class based views allowing you to generate PDF reports using html or latex templates. Django Persian PDF under the hood uses two compiler to render template and build the actual pdf file:
Xelatex
Google Chrome
Using this approach avoids regular overhead for parsing html tags, improving overall response time and memory usage when generating large pdf files. Django Persian PDF follows django class based views and base on the compilers provide 4 generic view classes. The only difference is that these classes render their associated template and return a pdf file as response. Just like django views you can pass queryset or make context to be used in template. Here are the view classes available in django_persian_pdf:
HTMLToPDFTemplateView is an extension of django TemplateView using .html template to generate pdf file.
HTMLToPDFDetailView is an extension of django DetailView using .html template to generate pdf file.
LatexToPDFTemplateView is an extension of django TemplateView using .tex template to generate pdf file.
LatexToPDFDetailView is an extension of django DetailView using .tex template to generate pdf file.
Status
Dependencies
Django >= 3.2
Google Chrome Stable
xelatex
Install
pip install django-persian-pdf
Make sure you have installed either google-chrome-stable or texlive-xetex on your machine.
sudo apt install google-chrome-stable
sudo apt install texlive-xetex
Usage
Edit settings.py and add django_persian_pdf to your INSTALLED_APPS.
Inherit your views from appropriate Template or Detail view classes.
Example #1: Using HTML Template to generate a PDF response
from django_persian_pdf import views as pdf_views
class TemplatePrint(pdf_views.HTMLToPDFTemplateView):
template_name = 'payment_reports.html'
def get_context_data(self, **kwargs):
context = super().get_context_data()
context['payments'] = Payments.objects.all()
return context
class DetailPrint(pdf_views.HTMLToPDFDetailView):
template_name = 'payment_detail.html'
queryset = Payments.objects.all()
Example #2: Using LaTeX Template to generate a PDF response
from django_persian_pdf import views as pdf_views
class TemplatePrint(pdf_views.LatexToPDFTemplateView):
template_name = 'payment_reports.tex'
def get_context_data(self, **kwargs):
context = super().get_context_data()
context['payments'] = Payments.objects.all()
return context
class DetailPrint(pdf_views.LatexToPDFDetailView):
template_name = 'payment_detail.tex'
queryset = Payments.objects.all()
Notes on LaTeX
Using latex template with persian fonts requires you to have installed your persian fonts in home directory.
mkdir ~/.fonts
cp /path_to_fonts/Vazirmatn.ttf ~/.fonts/
fc-cache -f -v
In latex template make sure you have used xepersian package as last package.
Define persian fonts in latex template.
You can use django template tags in latex template.
Here is an example of latex template for a given view:
\documentclass[a4paper,9pt]{letter}
\usepackage[portrait,margin=0.1in]{geometry}
\usepackage{xepersian}
\settextfont{Vazirmatn}
\setlatintextfont{Vazirmatn}
\setdigitfont[Scale=1.1]{Vazirmatn}
\begin{document}
{% for payment in payments %}
{{ payment.trace_code }}
\newline
{{ payment.amount }}
\newline
{% endfor %}
\end{document}
Metadata
Release files for django-persian-pdf 0.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 | |
|---|---|---|---|---|
| django_persian_pdf-0.1.3.tar.gz | 7.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_persian_pdf-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.5 kB
Release files / django_persian_pdf-0.1.3.tar.gz
| Download URL | django_persian_pdf-0.1.3.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52548ccb6bf1a232c42d73e41fa94df13fcdbf60f4a5cda0146fe8a5c43a364d
|
|
BLAKE2b-256 checksum How to use checksums |
1c5620c55b543e4db43a43bc2a61727d3405d670fef42254887bb171c1848ef5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.4
|
Release files / django_persian_pdf-0.1.3-py3-none-any.whl
| Download URL | django_persian_pdf-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
073e5f8560a5da3770901e8c21a47749f3709a7cd783066f034a01e1fd32ecd8
|
|
BLAKE2b-256 checksum How to use checksums |
ba70273bcefad31e27baa692d67db9760cdbb2554f07eff82144fc2ac4c642d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.4
|
Security for django-persian-pdf 0.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.