=============================
Django Endesive
=============================

.. image:: https://badge.fury.io/py/django-endesive.svg
    :target: https://badge.fury.io/py/django-endesive

.. image:: https://travis-ci.org/zengoma/django-endesive.svg?branch=master
    :target: https://travis-ci.org/zengoma/django-endesive

.. image:: https://codecov.io/gh/zengoma/django-endesive/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/zengoma/django-endesive

Django endesive PDF digital signing utility. This package allows you to digitally sign a PDF document from your Django
application. It is based on https://github.com/m32/endesive

In order to digitally sign your pdf documents you will need a valid p12 / pfx certificate. You can use a self-signed
certificate for testing purposes but you should aquire a certificate from a Certificate Authority for production.

Special PDF certificates issued by partners on the `AATL <https://helpx.adobe.com/africa/acrobat/kb/approved-trust-list1.html>`_
(Adobe Approved Trust List).

Documentation
-------------

The full documentation is at https://django-endesive.readthedocs.io.

Quickstart
----------

Install Django Endesive::

    pip install django-endesive

Add it to your `INSTALLED_APPS`:

.. code-block:: python

    INSTALLED_APPS = (
        ...
        'django_endesive.apps.DjangoEndesiveConfig',
        ...
    )



Add the following to your setup to your settings.py file:

.. code-block:: python

    DJANGO_ENDESIVE = {
        'PDF_CERTIFICATE_PATH': 'required: /path/to/your/certificate',
        'PDF_CERTIFICATE_PASSWORD': 'optional: certificate password if applicable',
        'PDF_ATTRIBUTES': {
            'CONTACT': 'optional: <you@example.com>',
            'LOCATION': 'optional: <your location>',
            'REASON': 'optional: <Reason for Document validation>'
        }
    }


Here is a rather contrived example of how you would sign your pdf:

.. code-block:: python

    from django_endesive import pdf
    from endesive.pdf import fpdf

    # Generate a pdf file (this could be any file already generated by your app)
    doc = fpdf.FPDF()
    doc.add_page()
    doc.set_font('helvetica', '', 13.0)
    doc.cell(w=75.0, h=22.0, align='C',
                  txt='Hello, world page=1.', border=0, ln=0)
    doc.output('./pdf.pdf', "F")

    # Open file and feed bytes to the sign function
    pdf_bytes = open('./pdf.pdf', 'rb').read()

    signed_pdf = pdf.sign(pdf_bytes=pdf_bytes)

    # signed_pdf bytes can now be written to a bytestream in memory or saved to a file on disk

Running Tests
-------------

Does the code actually work?

::

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install tox
    (myenv) $ tox

Credits
-------

Tools used in rendering this package:

*  Cookiecutter_
*  `cookiecutter-djangopackage`_
*  Endesive_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage
.. _Endesive: https://github.com/m32/endesive/blob/master/examples/pdf-sign-cms.py

Author
-------
* This project was created by Lance Moore from `Engineer ROI <https://engineerroi.com>`_.
