Skip to main content

Templating and pdf generation for docx/pptx files

Project description

=========
Burocracy
=========

Burocracy is a library that allows you to use .docx templates as
templates using MailMerge fields and can save them as docx's or pdfs. It
can insert plain text, images, tables and (simple) HTML. See
`django-bureaucracy`_ for some mild django integration.

WIP: PPTX as templates.

Usage
=====

Example
-------

.. code-block::

from bureaucracy import DocxTemplate, HTML, Image, Table

doc = DocxTemplate('examples/sample.docx')

context = {
'table': Table(data=[['this is the first cell of the first row', 'this is the second cell of the first row'],
['the second row', 'etc'],
['etc', 'etc]],
headers=['header 1', 'header 2']),
'image': Image('pigeon.jpg')
'html': HTML(<p><strong>bold</strong>-notbold</p><ul><li>hop</li><li>la</li><li>kee</li></ul>")
'text': 'some text',
}

doc.render_and_save('generated.docx', context)
doc.render_and_save('generated.pdf', context, format='pdf')


Inserting mail merge fields
---------------------------

Bureaucracy expects the .docx-files passed to the ``DocxTemplate`` constructor
to contain MailMerge fields whose names correspond to the ones used
in the context dict. How this is done exactly depends on the version of
Office you have, but it seems that it's always a variation on
Insert > Field > Mail Merge > Mergefield and then entering the name:

.. figure:: docs/mailmerge_mac.png?raw=true
:alt: Mailmerge on Mac

What it looks like on Office Mac 2015


Installation
============

.. code-block:: bash

pip install burocracy


Note that although this will install the pypandoc dependency, that package
makes use of the pandoc executable whose installation sometimes fails.
To work around this, install pandoc on it's own with your favorite package
manager and make it available on the path.

For the pdf generation, bureaucracy needs the LibreOffice ``soffice`` executable
to be installed and on the path.


.. _django-bureacracy: https://bitbucket.org/maykinmedia/django-bureaucracy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

burocracy-0.3.2.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

burocracy-0.3.2-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file burocracy-0.3.2.tar.gz.

File metadata

  • Download URL: burocracy-0.3.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for burocracy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 a32c2462224b4cb52c272086d07fa7b633a30ffab71f4673edc7955e3896fdc5
MD5 56181174202252c845f7d33eebb6c5e0
BLAKE2b-256 e7a32baa6d02cf1897d759e24c11c1d2bbe62496b56afaafbf37154b10c23f2f

See more details on using hashes here.

File details

Details for the file burocracy-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for burocracy-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e3aac09ad2bde6490d2b70132c1c5789a13973e0aaab3a6096d92813004d2a3d
MD5 f59551518a520e6b4dee41790be3fa4c
BLAKE2b-256 10fb61ff8f6f4c7363113d46829de74091c76089a71ceecaead51c829c5706e4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page