Generate PDF, MS Word and Excel documents from templates in Django
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github Cookiecutter-generated initial structure. Jun 10, 2016
ci
docs Some cosmetic changes. Jul 20, 2016
example
templated_docs
tests Make Travis know the path LibreOffice is installed to. Jul 13, 2016
.editorconfig
.gitignore Relatively stable convertor. Jul 11, 2016
.travis.yml Make package work with Django 1.10. Oct 17, 2016
AUTHORS.rst Cookiecutter-generated initial structure. Jun 10, 2016
CONTRIBUTING.rst
HISTORY.rst
LICENSE
MANIFEST.in Cookiecutter-generated initial structure. Jun 10, 2016
Makefile
README.rst Make package work with Django 1.10. Oct 17, 2016
requirements_dev.txt
setup.cfg Bump version: 0.3.0 → 0.3.1 Oct 17, 2016
setup.py Bump version: 0.3.0 → 0.3.1 Oct 17, 2016
tox.ini Make package work with Django 1.10. Oct 17, 2016
travis_pypi_setup.py Corrected the repo name. Jun 10, 2016

README.rst

Templated-docs

Documentation Status Dependencies

Generate templated documents within Django in any format supported by LibreOffice: texts, spreadsheets, presentations etc.

Requirements

  • Python 2.7 or 3.4+
  • Django >= 1.8
  • A recent LibreOffice version (>=4.3.0) supporting LibreOfficeKit API.

Example usage

Create a sample.odt document (make sure it's in OpenDocument format) and put it in your Django templates folder. It should look something like this:

https://github.com/alexmorozov/templated-docs/raw/master/docs/document-template.png

Then write a view to generate documents from this template:

from templated_docs import fill_template
from templated_docs.http import FileResponse

def get_document(request):
    """
    A view to get a document filled with context variables.
    """
    context = {'user': request.user}  # Just an example

    filename = fill_template('sample.odt', context, output_format='pdf')
    visible_filename = 'greeting.pdf'

    return FileResponse(filename, visible_filename)

Navigate to the url your view is connected to, and you'll see a rendered and converted document:

https://github.com/alexmorozov/templated-docs/raw/master/docs/generated-document.png

For more examples, see the examples/ subfolder in the repository. More detailed documentation is available on https://templated-docs.readthedocs.io.

Credits

Templated-docs was written by Alex Morozov.

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.