django-persian-pdf


Namedjango-persian-pdf JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryDjango class based views to generate pdf files using html or latex template.
upload_time2024-05-17 14:32:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords pdf django persian xelatex
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Django Persian PDF
=========================

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
------

.. image:: https://img.shields.io/github/actions/workflow/status/bindruid/django-persian-pdf/test.yml.svg?branch=master
   :target: https://github.com/bindruid/django-persian-pdf/actions?workflow=Test

.. image:: https://img.shields.io/pypi/v/django-persian-pdf.svg
   :target: https://pypi.python.org/pypi/django-persian-pdf

.. image:: https://img.shields.io/pypi/pyversions/django-persian-pdf.svg
   :target: https://pypi.org/project/django-persian-pdf

.. image:: https://img.shields.io/pypi/djversions/django-persian-pdf.svg
   :target: https://pypi.org/project/django-persian-pdf/

Dependencies
------------

-  Django >= 3.2
-  Google Chrome Stable
-  xelatex

Install
-------

.. code-block:: bash

   pip install django-persian-pdf

- Make sure you have installed either ``google-chrome-stable`` or ``texlive-xetex`` on your machine.

.. code-block:: bash


   sudo apt install google-chrome-stable
   sudo apt install texlive-xetex

Usage
-----

1. Edit settings.py and add `django_persian_pdf` to your `INSTALLED_APPS`.

2. Inherit your views from appropriate Template or Detail view classes.

Example #1: Using HTML Template to generate a PDF response

.. code-block:: python

    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

.. code-block:: python

    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
----------------

1. Using latex template with persian fonts requires you to have installed your persian fonts in home directory.

.. code-block:: bash


   mkdir ~/.fonts
   cp /path_to_fonts/Vazirmatn.ttf ~/.fonts/
   fc-cache -f -v

2. In latex template make sure you have used ``xepersian`` package as last package.

3. Define persian fonts in latex template.

4. You can use django template tags in latex template.

Here is an example of latex template for a given view:

.. code-block:: latex

    \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}


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-persian-pdf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Ali Abharya <abharya.dev@gmail.com>",
    "keywords": "pdf, django, persian, xelatex",
    "author": null,
    "author_email": "Ali Abharya <abharya.dev@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1c/56/20c55b543e4db43a43bc2a61727d3405d670fef42254887bb171c1848ef5/django_persian_pdf-0.1.3.tar.gz",
    "platform": null,
    "description": "Django Persian PDF\n=========================\n\nDjango Persian PDF is a set of class based views allowing you to generate PDF reports\nusing html or latex templates.\nDjango Persian PDF under the hood uses two compiler to render template\nand build the actual pdf file:\n\n-  **Xelatex**\n-  **Google Chrome**\n\nUsing this approach avoids regular overhead for parsing html tags, improving overall\nresponse time and memory usage when generating large pdf files.\nDjango Persian PDF follows django class based views and base on the compilers provide 4 generic view classes.\nThe only difference is that these classes render their associated template and return a pdf file as response.\nJust like django views you can pass queryset or make context to be used in template.\nHere are the view classes available in **django_persian_pdf**:\n\n-  ``HTMLToPDFTemplateView`` is an extension of django ``TemplateView`` using ``.html`` template to generate pdf file.\n-  ``HTMLToPDFDetailView`` is an extension of django ``DetailView`` using ``.html`` template  to generate pdf file.\n-  ``LatexToPDFTemplateView`` is an extension of django ``TemplateView`` using ``.tex`` template to generate pdf file.\n-  ``LatexToPDFDetailView`` is an extension of django ``DetailView`` using ``.tex`` template to generate pdf file.\n\nStatus\n------\n\n.. image:: https://img.shields.io/github/actions/workflow/status/bindruid/django-persian-pdf/test.yml.svg?branch=master\n   :target: https://github.com/bindruid/django-persian-pdf/actions?workflow=Test\n\n.. image:: https://img.shields.io/pypi/v/django-persian-pdf.svg\n   :target: https://pypi.python.org/pypi/django-persian-pdf\n\n.. image:: https://img.shields.io/pypi/pyversions/django-persian-pdf.svg\n   :target: https://pypi.org/project/django-persian-pdf\n\n.. image:: https://img.shields.io/pypi/djversions/django-persian-pdf.svg\n   :target: https://pypi.org/project/django-persian-pdf/\n\nDependencies\n------------\n\n-  Django >= 3.2\n-  Google Chrome Stable\n-  xelatex\n\nInstall\n-------\n\n.. code-block:: bash\n\n   pip install django-persian-pdf\n\n- Make sure you have installed either ``google-chrome-stable`` or ``texlive-xetex`` on your machine.\n\n.. code-block:: bash\n\n\n   sudo apt install google-chrome-stable\n   sudo apt install texlive-xetex\n\nUsage\n-----\n\n1. Edit settings.py and add `django_persian_pdf` to your `INSTALLED_APPS`.\n\n2. Inherit your views from appropriate Template or Detail view classes.\n\nExample #1: Using HTML Template to generate a PDF response\n\n.. code-block:: python\n\n    from django_persian_pdf import views as pdf_views\n\n    class TemplatePrint(pdf_views.HTMLToPDFTemplateView):\n        template_name = 'payment_reports.html'\n\n        def get_context_data(self, **kwargs):\n            context = super().get_context_data()\n            context['payments'] = Payments.objects.all()\n            return context\n\n    class DetailPrint(pdf_views.HTMLToPDFDetailView):\n        template_name = 'payment_detail.html'\n        queryset = Payments.objects.all()\n\n\n\nExample #2: Using LaTeX Template to generate a PDF response\n\n.. code-block:: python\n\n    from django_persian_pdf import views as pdf_views\n\n    class TemplatePrint(pdf_views.LatexToPDFTemplateView):\n        template_name = 'payment_reports.tex'\n\n        def get_context_data(self, **kwargs):\n            context = super().get_context_data()\n            context['payments'] = Payments.objects.all()\n            return context\n\n    class DetailPrint(pdf_views.LatexToPDFDetailView):\n        template_name = 'payment_detail.tex'\n        queryset = Payments.objects.all()\n\nNotes on LaTeX\n----------------\n\n1. Using latex template with persian fonts requires you to have installed your persian fonts in home directory.\n\n.. code-block:: bash\n\n\n   mkdir ~/.fonts\n   cp /path_to_fonts/Vazirmatn.ttf ~/.fonts/\n   fc-cache -f -v\n\n2. In latex template make sure you have used ``xepersian`` package as last package.\n\n3. Define persian fonts in latex template.\n\n4. You can use django template tags in latex template.\n\nHere is an example of latex template for a given view:\n\n.. code-block:: latex\n\n    \\documentclass[a4paper,9pt]{letter}\n    \\usepackage[portrait,margin=0.1in]{geometry}\n    \\usepackage{xepersian}\n\n    \\settextfont{Vazirmatn}\n    \\setlatintextfont{Vazirmatn}\n    \\setdigitfont[Scale=1.1]{Vazirmatn}\n\n\n    \\begin{document}\n\n      {% for payment in payments %}\n        {{ payment.trace_code }}\n        \\newline\n        {{ payment.amount }}\n        \\newline\n      {% endfor %}\n\n    \\end{document}\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django class based views to generate pdf files using html or latex template.",
    "version": "0.1.3",
    "project_urls": {
        "Changelog": "https://github.com/bindruid/django-persian-pdf/blob/master/CHANGELOG.rst",
        "Repository": "https://github.com/bindruid/django-persian-pdf"
    },
    "split_keywords": [
        "pdf",
        " django",
        " persian",
        " xelatex"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba70273bcefad31e27baa692d67db9760cdbb2554f07eff82144fc2ac4c642d3",
                "md5": "711f41a6e1b0e6e867562840d000d537",
                "sha256": "073e5f8560a5da3770901e8c21a47749f3709a7cd783066f034a01e1fd32ecd8"
            },
            "downloads": -1,
            "filename": "django_persian_pdf-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "711f41a6e1b0e6e867562840d000d537",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6604,
            "upload_time": "2024-05-17T14:32:14",
            "upload_time_iso_8601": "2024-05-17T14:32:14.103636Z",
            "url": "https://files.pythonhosted.org/packages/ba/70/273bcefad31e27baa692d67db9760cdbb2554f07eff82144fc2ac4c642d3/django_persian_pdf-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c5620c55b543e4db43a43bc2a61727d3405d670fef42254887bb171c1848ef5",
                "md5": "2e072f0d15b0e56dbde41865b548245e",
                "sha256": "52548ccb6bf1a232c42d73e41fa94df13fcdbf60f4a5cda0146fe8a5c43a364d"
            },
            "downloads": -1,
            "filename": "django_persian_pdf-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2e072f0d15b0e56dbde41865b548245e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 7857,
            "upload_time": "2024-05-17T14:32:18",
            "upload_time_iso_8601": "2024-05-17T14:32:18.757153Z",
            "url": "https://files.pythonhosted.org/packages/1c/56/20c55b543e4db43a43bc2a61727d3405d670fef42254887bb171c1848ef5/django_persian_pdf-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-17 14:32:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bindruid",
    "github_project": "django-persian-pdf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-persian-pdf"
}
        
Elapsed time: 0.22080s