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
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.2.2.tar.gz
(13.6 kB
view details)
Built Distribution
burocracy-0.2.2-py3-none-any.whl
(18.1 kB
view details)
File details
Details for the file burocracy-0.2.2.tar.gz
.
File metadata
- Download URL: burocracy-0.2.2.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4571a73cbb4ab575970816da540ea28361efb92424570484f1a3ef40deedd642 |
|
MD5 | 5981cbb8f0fac0a7bcd8c7bd7e1684f5 |
|
BLAKE2b-256 | dbbf654a48fd21d732cec3d72792db99336ad4ad3d9bf5420b9da8d71cf6ac65 |
Provenance
File details
Details for the file burocracy-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: burocracy-0.2.2-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69085b35dee43b7c80f80f6c7d74671676960627a426351a248696e2c9d6fcb3 |
|
MD5 | c03fa10993559e43912b07843a01671c |
|
BLAKE2b-256 | 7ed7d794f0c2faf9275919f71cb9f3af85fadfc2f97a988d8a10baf7aa38677d |