docx-mergefields


Namedocx-mergefields JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttp://github.com/iulica/docx-mergefields
SummaryReplaces fields in docx (Microsoft Office Word) files
upload_time2024-05-17 09:16:22
maintainerNone
docs_urlNone
authorIulian Ciorăscu
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =================
docx Merge Fields
=================

.. image:: https://badge.fury.io/py/docx-mergefields.png
    :alt: PyPI
    :target: https://pypi.python.org/pypi/docx-mergefields

Udpates the MAILMERGE fields in Office Open XML (docx) files. Can be used on any
system without having to install Microsoft Office Word. Supports Python 3.7 and up.
For the moment only the INCLUDEPICTURE fields are supported.

It supports local images, URLs and base64 image encoded strings. Also, it allows 
the resize of the image both in width and height.

The fields are *replaced* so afterwards they cannot be updated anymore.

This library uses the excellent `python-docx`_ library.

Also, it is better used after mailmerging the INCLUDEPICTURE fields using the 
`docx-mailmerge2`_ library.


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

Installation with ``pip``:
::

    $ pip install docx-mergefields


Usage
=====

Open the file.
::

    from mergefields import MergeFieldsDocument
    with MergeFieldsDocument("../documents/mailmerge_doc.docx") as doc:
      doc.transform_fields()
      doc.doc.save("../documents/merged_doc.docx")


Examples
========

From local file, original size:
::

  { INCLUDEPICTURE "./filename.jpg" }

From a URL, resize width to the given size, resize height to 
preserving the aspect ratio:
::

  { INCLUDEPICTURE "https://www.pngall.com/wp-content/uploads/8/Sample-Watermark-PNG-Image.png" \w 200 }

From a base64 URI, resize both width and height to the given value
(aspect ratio is not preserved):
::

  { INCLUDEPICTURE "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQMAAADCCAMAAAB6zFdcAAAAtFBMVEX///9QUU/yX1xKS0mKiopNTkxCQ0FGR0VpamjS0tJHSEa9vbyvr67yXFlSU1FDRELyWVaoqKjc3N3xU1D19fXDxMNWV1XxUU797Ovv7+/j4+P3pKP5vLv+8/O3t7b71NP1i4nzc3D4rqz1hYPzZ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b1VB0l0gGTaGRESK5JXVSkGQ7lvnGUj4UbfN8pnbbJ0SxhMXIM1adavKSNetxLX4tpkf3W6MWDPlzqx+7ml8wPPeaDEOFy+yqDcq2+p00Le6MRvh2DQYozODyLVYK6btLJWGyxaMj2V7nZk1BnGNduWKH9UR0f+eDYbe748T/PSr7VkEEzXEodo8lCJdYOkx/p7M7Cy4yRKJPm75c6ZjoOX8pdND3GYHSmnB4rJTBBa21LyFyGoveUXx4JYLxiM/myU8qW+qzyWQzFQp2k6ei+mOtnJOo0ITh2Xm6RO7ha0bpRvkdOMwZYV8ZasefHyISguHIM6t5IjZca7st9PPG7BLNzDtBmzaDnxZpfudgIxmNSLJslTvCj8+8Ki+N0gmpqWy127u17pzRUTf0TNihzxVL7boeXmabjLzQZ/s/ei/mAwOHySUH07bTY4r59f/y2Ns9lQ2kGdi0U6G/z3Y/+Wo9n4aibMPr/22xo55z0ThB7NhvD22L/jqMQholc6WjwzM4fOEM9X0O//5Yd/9/vfeRn0kX5b+PXP4y/64wQ2+n9c0C6o+P+B93uC/iDp/2BwlhEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAID/61/qyEpXq0NhcQAAAABJRU5ErkJggg==" \w 200 \h 200 }


Todo / Wish List
================

* Include other fields
* Update the fields instead of replacing them

Contributing
============

* Fork the repository on GitHub and start hacking
* Create / fix the unit tests
* Send a pull request with your changes

Unit tests
----------

In order to make sure that the library performs the way it was designed, unit
tests are used. When providing new features, or fixing bugs, there should be a
unit test that demonstrates it. Run the test suite::

    python -m unittest discover

Credits
=======

| This repository is written and maintained by `Iulian Ciorăscu`_.

.. _python-docx: https://pypi.org/project/python-docx/
.. _docx-mailmerge2: https://github.com/iulica/docx-mailmerge
.. _Iulian Ciorăscu: https://github.com/iulica/

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/iulica/docx-mergefields",
    "name": "docx-mergefields",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Iulian Cior\u0103scu",
    "author_email": "ciulian@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ec/59/7833d4123853603972a5d25277840c1b7150bb5c0fafcfab50bbb8e4238a/docx_mergefields-0.1.3.tar.gz",
    "platform": null,
    "description": "=================\ndocx Merge Fields\n=================\n\n.. image:: https://badge.fury.io/py/docx-mergefields.png\n    :alt: PyPI\n    :target: https://pypi.python.org/pypi/docx-mergefields\n\nUdpates the MAILMERGE fields in Office Open XML (docx) files. Can be used on any\nsystem without having to install Microsoft Office Word. Supports Python 3.7 and up.\nFor the moment only the INCLUDEPICTURE fields are supported.\n\nIt supports local images, URLs and base64 image encoded strings. Also, it allows \nthe resize of the image both in width and height.\n\nThe fields are *replaced* so afterwards they cannot be updated anymore.\n\nThis library uses the excellent `python-docx`_ library.\n\nAlso, it is better used after mailmerging the INCLUDEPICTURE fields using the \n`docx-mailmerge2`_ library.\n\n\nInstallation\n============\n\nInstallation with ``pip``:\n::\n\n    $ pip install docx-mergefields\n\n\nUsage\n=====\n\nOpen the file.\n::\n\n    from mergefields import MergeFieldsDocument\n    with MergeFieldsDocument(\"../documents/mailmerge_doc.docx\") as doc:\n      doc.transform_fields()\n      doc.doc.save(\"../documents/merged_doc.docx\")\n\n\nExamples\n========\n\nFrom local file, original size:\n::\n\n  { INCLUDEPICTURE \"./filename.jpg\" }\n\nFrom a URL, resize width to the given size, resize height to \npreserving the aspect ratio:\n::\n\n  { INCLUDEPICTURE \"https://www.pngall.com/wp-content/uploads/8/Sample-Watermark-PNG-Image.png\" \\w 200 }\n\nFrom a base64 URI, resize both width and height to the given value\n(aspect ratio is not preserved):\n::\n\n  { INCLUDEPICTURE \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQMAAADCCAMAAAB6zFdcAAAAtFBMVEX///9QUU/yX1xKS0mKiopNTkxCQ0FGR0VpamjS0tJHSEa9vbyvr67yXFlSU1FDRELyWVaoqKjc3N3xU1D19fXDxMNWV1XxUU797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nHTDILpSHAjpp7lZikGaHaoUA5oM3kwv2tB+Qe6eaR1o2Ppieb1VB0l0gGTaGRESK5JXVSkGQ7lvnGUj4UbfN8pnbbJ0SxhMXIM1adavKSNetxLX4tpkf3W6MWDPlzqx+7ml8wPPeaDEOFy+yqDcq2+p00Le6MRvh2DQYozODyLVYK6btLJWGyxaMj2V7nZk1BnGNduWKH9UR0f+eDYbe748T/PSr7VkEEzXEodo8lCJdYOkx/p7M7Cy4yRKJPm75c6ZjoOX8pdND3GYHSmnB4rJTBBa21LyFyGoveUXx4JYLxiM/myU8qW+qzyWQzFQp2k6ei+mOtnJOo0ITh2Xm6RO7ha0bpRvkdOMwZYV8ZasefHyISguHIM6t5IjZca7st9PPG7BLNzDtBmzaDnxZpfudgIxmNSLJslTvCj8+8Ki+N0gmpqWy127u17pzRUTf0TNihzxVL7boeXmabjLzQZ/s/ei/mAwOHySUH07bTY4r59f/y2Ns9lQ2kGdi0U6G/z3Y/+Wo9n4aibMPr/22xo55z0ThB7NhvD22L/jqMQholc6WjwzM4fOEM9X0O//5Yd/9/vfeRn0kX5b+PXP4y/64wQ2+n9c0C6o+P+B93uC/iDp/2BwlhEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAID/61/qyEpXq0NhcQAAAABJRU5ErkJggg==\" \\w 200 \\h 200 }\n\n\nTodo / Wish List\n================\n\n* Include other fields\n* Update the fields instead of replacing them\n\nContributing\n============\n\n* Fork the repository on GitHub and start hacking\n* Create / fix the unit tests\n* Send a pull request with your changes\n\nUnit tests\n----------\n\nIn order to make sure that the library performs the way it was designed, unit\ntests are used. When providing new features, or fixing bugs, there should be a\nunit test that demonstrates it. Run the test suite::\n\n    python -m unittest discover\n\nCredits\n=======\n\n| This repository is written and maintained by `Iulian Cior\u0103scu`_.\n\n.. _python-docx: https://pypi.org/project/python-docx/\n.. _docx-mailmerge2: https://github.com/iulica/docx-mailmerge\n.. _Iulian Cior\u0103scu: https://github.com/iulica/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Replaces fields in docx (Microsoft Office Word) files",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "http://github.com/iulica/docx-mergefields"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "349c1d991a1acb363c22000ede41d4bd2c355c91d771dad7b49504a7df86473c",
                "md5": "48341295777896e00baa9a3aa3c617e8",
                "sha256": "5185a9a166abb1d720cc66e6a7ed26129720c2015d5d946aab59b347ba645f36"
            },
            "downloads": -1,
            "filename": "docx_mergefields-0.1.3-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "48341295777896e00baa9a3aa3c617e8",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8029,
            "upload_time": "2024-05-17T09:16:20",
            "upload_time_iso_8601": "2024-05-17T09:16:20.667241Z",
            "url": "https://files.pythonhosted.org/packages/34/9c/1d991a1acb363c22000ede41d4bd2c355c91d771dad7b49504a7df86473c/docx_mergefields-0.1.3-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ec597833d4123853603972a5d25277840c1b7150bb5c0fafcfab50bbb8e4238a",
                "md5": "852afe3440667b3dcff7ced8732b6952",
                "sha256": "2df2e352477fc33edbc4c82adf13775225b915b1e556a7e5625535665897fd10"
            },
            "downloads": -1,
            "filename": "docx_mergefields-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "852afe3440667b3dcff7ced8732b6952",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8363,
            "upload_time": "2024-05-17T09:16:22",
            "upload_time_iso_8601": "2024-05-17T09:16:22.251463Z",
            "url": "https://files.pythonhosted.org/packages/ec/59/7833d4123853603972a5d25277840c1b7150bb5c0fafcfab50bbb8e4238a/docx_mergefields-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-17 09:16:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "iulica",
    "github_project": "docx-mergefields",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "docx-mergefields"
}
        
Elapsed time: 1.56323s