pdf417gen


Namepdf417gen JSON
Version 0.8.0 PyPI version JSON
download
home_pageNone
SummaryPDF417 2D barcode generator for Python
upload_time2024-07-04 14:24:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licensePDF417-Py License Copyright (c) 2016 Ivan Habunek <ivan.habunek@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords pdf417 2d barcode generator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===================================
PDF417 barcode generator for Python
===================================

.. image:: https://img.shields.io/travis/ihabunek/pdf417-py.svg?maxAge=3600&style=flat-square
   :target: https://travis-ci.org/ihabunek/pdf417-py
.. image:: https://img.shields.io/badge/author-%40ihabunek-blue.svg?maxAge=3600&style=flat-square
   :target: https://twitter.com/ihabunek
.. image:: https://img.shields.io/github/license/ihabunek/pdf417-py.svg?maxAge=3600&style=flat-square
   :target: https://opensource.org/licenses/MIT
.. image:: https://img.shields.io/pypi/v/pdf417gen.svg?maxAge=3600&style=flat-square
   :target: https://pypi.python.org/pypi/pdf417gen


Easily encode your data into a 2D barcode using the PDF417 format.

.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/1_basic.jpg

Licensed under the MIT License, see `LICENSE <LICENSE>`_.

Installation
------------

Install using pip:

.. code-block::

    pip install pdf417gen


CLI
---

The ``pdf417gen`` command can be used to generate a barcode from commandline. It
takes the input either as an argument or from stdin.

.. code-block:: bash

    # Show help
    pdf417gen encode --help

    # Encode given text and display the barcode
    pdf417gen encode "Beautiful is better than ugly"

    # Encode given text and save barcode to a file (extension determines format)
    pdf417gen encode -o barcode.png "Explicit is better than implicit"

    # Input from a file
    pdf417gen encode < input.txt

    # Piped input
    python -c "import this" | pdf417gen encode


Usage
-----

Creating bar codes is done in two steps:

* Encode a string to a list of code words using ``encode()``
* Render the barcode using one of the rendering functions: ``render_image()``,
  ``render_svg()``.

Usage overview:

.. code-block:: python

    from pdf417gen import encode, render_image, render_svg

    # Some data to encode
    text = """Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated."""

    # Convert to code words
    codes = encode(text)

    # Generate barcode as image
    image = render_image(codes)  # Pillow Image object
    image.save('barcode.jpg')

    # Generate barcode as SVG
    svg = render_svg(codes)  # ElementTree object
    svg.write("barcode.svg")


Supports unicode:

.. code-block:: python

    # These two inputs encode to the same code words
    encode("love 💔")
    encode(b"love \xf0\x9f\x92\x94")

    # Default encoding is UTF-8, but you can specify your own
    encode("love 💔", encoding="utf-8")


Encoding data
-------------

The first step is to encode your data to a list of code words.

.. code-block:: python

    encode(data, columns=6, security_level=2Ë™)

Columns
~~~~~~~

The bar code size can be customized by defining the number of columns used to
render the data, between 1 and 30, the default value is 6. A bar code can have a
maximum of 90 rows, so for larger data sets you may need to increase the number
of columns to decrease the rows count.

.. code-block:: python

    codes = encode(text, columns=12)
    image = render_image(codes)
    image.show()

.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/2_columns.jpg

Security level
~~~~~~~~~~~~~~

Increasing the security level will produce stronger (and more numerous) error
correction codes, making the bar code larger, but less prone to corruption. The
security level can range from 0 to 8, and procuces ``2^(level+1)`` error
correction code words, meaning level 0 produces 2 code words and level 8
produces 512. The default security level is 2.

.. code-block:: python

    codes = encode(text, columns=12, security_level=6)
    image = render_image(codes)
    image.show()

.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/3_security_level.jpg

Render image
------------

The ``render_image`` function takes the following options:

* ``scale`` - module width, in pixels (default: 3)
* ``ratio`` - module height to width ratio (default: 3)
* ``padding`` - image padding, in pixels (default: 20)
* ``fg_color`` - foreground color (default: ``#000000``)
* ``bg_color`` - background color (default: ``#FFFFFF``)

.. note::

   A module is the smallest element of a barcode, analogous to a pixel. Modules
   in a PDF417 bar code are tall and narrow.

The function returns a Pillow Image_ object containing the barcode.

Colors can be specified as hex codes or using HTML color names.

.. code-block:: python

    codes = encode(text, columns=3)
    image = render_image(codes, scale=5, ratio=2, padding=5, fg_color="Indigo", bg_color="#ddd")
    image.show()

.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/4_rendering.jpg

Render SVG
----------

The ``render_svg`` function takes the following options:

* ``scale`` - module width, in pixels (default: 3)
* ``ratio`` - module height to width ratio (default: 3)
* ``padding`` - image padding, in pixels (default: 20)
* ``color`` - foreground color (default: `#000000`)

The function returns a ElementTree_ object containing the barcode in SVG format.

Unlike ``render_image``, this function does not take a background color option.
The background is left transparent.

.. code-block:: python

    codes = encode(text, columns=3)
    svg = render_svg(codes, scale=5, ratio=2, color="Seaweed")
    svg.write('barcode.svg')

See also
--------

* pdf417-php_ - a PHP implementation
* golang-pdf417_ - a Go implementation

.. _pdf417-php: https://github.com/ihabunek/pdf417-php
.. _golang-pdf417: https://github.com/ruudk/golang-pdf417
.. _ElementTree: https://docs.python.org/3.5/library/xml.etree.elementtree.html#elementtree-objects
.. _Image: https://pillow.readthedocs.io/en/3.2.x/reference/Image.html

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pdf417gen",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "pdf417, 2d, barcode, generator",
    "author": null,
    "author_email": "Ivan Habunek <ivan@habunek.com>",
    "download_url": "https://files.pythonhosted.org/packages/8f/4c/2d82079abbd2ca93e531b3d75947b704cf21fabd96a3b6c91adcb79a3464/pdf417gen-0.8.0.tar.gz",
    "platform": null,
    "description": "===================================\nPDF417 barcode generator for Python\n===================================\n\n.. image:: https://img.shields.io/travis/ihabunek/pdf417-py.svg?maxAge=3600&style=flat-square\n   :target: https://travis-ci.org/ihabunek/pdf417-py\n.. image:: https://img.shields.io/badge/author-%40ihabunek-blue.svg?maxAge=3600&style=flat-square\n   :target: https://twitter.com/ihabunek\n.. image:: https://img.shields.io/github/license/ihabunek/pdf417-py.svg?maxAge=3600&style=flat-square\n   :target: https://opensource.org/licenses/MIT\n.. image:: https://img.shields.io/pypi/v/pdf417gen.svg?maxAge=3600&style=flat-square\n   :target: https://pypi.python.org/pypi/pdf417gen\n\n\nEasily encode your data into a 2D barcode using the PDF417 format.\n\n.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/1_basic.jpg\n\nLicensed under the MIT License, see `LICENSE <LICENSE>`_.\n\nInstallation\n------------\n\nInstall using pip:\n\n.. code-block::\n\n    pip install pdf417gen\n\n\nCLI\n---\n\nThe ``pdf417gen`` command can be used to generate a barcode from commandline. It\ntakes the input either as an argument or from stdin.\n\n.. code-block:: bash\n\n    # Show help\n    pdf417gen encode --help\n\n    # Encode given text and display the barcode\n    pdf417gen encode \"Beautiful is better than ugly\"\n\n    # Encode given text and save barcode to a file (extension determines format)\n    pdf417gen encode -o barcode.png \"Explicit is better than implicit\"\n\n    # Input from a file\n    pdf417gen encode < input.txt\n\n    # Piped input\n    python -c \"import this\" | pdf417gen encode\n\n\nUsage\n-----\n\nCreating bar codes is done in two steps:\n\n* Encode a string to a list of code words using ``encode()``\n* Render the barcode using one of the rendering functions: ``render_image()``,\n  ``render_svg()``.\n\nUsage overview:\n\n.. code-block:: python\n\n    from pdf417gen import encode, render_image, render_svg\n\n    # Some data to encode\n    text = \"\"\"Beautiful is better than ugly.\n    Explicit is better than implicit.\n    Simple is better than complex.\n    Complex is better than complicated.\"\"\"\n\n    # Convert to code words\n    codes = encode(text)\n\n    # Generate barcode as image\n    image = render_image(codes)  # Pillow Image object\n    image.save('barcode.jpg')\n\n    # Generate barcode as SVG\n    svg = render_svg(codes)  # ElementTree object\n    svg.write(\"barcode.svg\")\n\n\nSupports unicode:\n\n.. code-block:: python\n\n    # These two inputs encode to the same code words\n    encode(\"love \ud83d\udc94\")\n    encode(b\"love \\xf0\\x9f\\x92\\x94\")\n\n    # Default encoding is UTF-8, but you can specify your own\n    encode(\"love \ud83d\udc94\", encoding=\"utf-8\")\n\n\nEncoding data\n-------------\n\nThe first step is to encode your data to a list of code words.\n\n.. code-block:: python\n\n    encode(data, columns=6, security_level=2\u02d9)\n\nColumns\n~~~~~~~\n\nThe bar code size can be customized by defining the number of columns used to\nrender the data, between 1 and 30, the default value is 6. A bar code can have a\nmaximum of 90 rows, so for larger data sets you may need to increase the number\nof columns to decrease the rows count.\n\n.. code-block:: python\n\n    codes = encode(text, columns=12)\n    image = render_image(codes)\n    image.show()\n\n.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/2_columns.jpg\n\nSecurity level\n~~~~~~~~~~~~~~\n\nIncreasing the security level will produce stronger (and more numerous) error\ncorrection codes, making the bar code larger, but less prone to corruption. The\nsecurity level can range from 0 to 8, and procuces ``2^(level+1)`` error\ncorrection code words, meaning level 0 produces 2 code words and level 8\nproduces 512. The default security level is 2.\n\n.. code-block:: python\n\n    codes = encode(text, columns=12, security_level=6)\n    image = render_image(codes)\n    image.show()\n\n.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/3_security_level.jpg\n\nRender image\n------------\n\nThe ``render_image`` function takes the following options:\n\n* ``scale`` - module width, in pixels (default: 3)\n* ``ratio`` - module height to width ratio (default: 3)\n* ``padding`` - image padding, in pixels (default: 20)\n* ``fg_color`` - foreground color (default: ``#000000``)\n* ``bg_color`` - background color (default: ``#FFFFFF``)\n\n.. note::\n\n   A module is the smallest element of a barcode, analogous to a pixel. Modules\n   in a PDF417 bar code are tall and narrow.\n\nThe function returns a Pillow Image_ object containing the barcode.\n\nColors can be specified as hex codes or using HTML color names.\n\n.. code-block:: python\n\n    codes = encode(text, columns=3)\n    image = render_image(codes, scale=5, ratio=2, padding=5, fg_color=\"Indigo\", bg_color=\"#ddd\")\n    image.show()\n\n.. image:: https://raw.githubusercontent.com/ihabunek/pdf417-py/master/images/4_rendering.jpg\n\nRender SVG\n----------\n\nThe ``render_svg`` function takes the following options:\n\n* ``scale`` - module width, in pixels (default: 3)\n* ``ratio`` - module height to width ratio (default: 3)\n* ``padding`` - image padding, in pixels (default: 20)\n* ``color`` - foreground color (default: `#000000`)\n\nThe function returns a ElementTree_ object containing the barcode in SVG format.\n\nUnlike ``render_image``, this function does not take a background color option.\nThe background is left transparent.\n\n.. code-block:: python\n\n    codes = encode(text, columns=3)\n    svg = render_svg(codes, scale=5, ratio=2, color=\"Seaweed\")\n    svg.write('barcode.svg')\n\nSee also\n--------\n\n* pdf417-php_ - a PHP implementation\n* golang-pdf417_ - a Go implementation\n\n.. _pdf417-php: https://github.com/ihabunek/pdf417-php\n.. _golang-pdf417: https://github.com/ruudk/golang-pdf417\n.. _ElementTree: https://docs.python.org/3.5/library/xml.etree.elementtree.html#elementtree-objects\n.. _Image: https://pillow.readthedocs.io/en/3.2.x/reference/Image.html\n",
    "bugtrack_url": null,
    "license": "PDF417-Py License  Copyright (c) 2016 Ivan Habunek <ivan.habunek@gmail.com>  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "PDF417 2D barcode generator for Python",
    "version": "0.8.0",
    "project_urls": {
        "Homepage": "https://github.com/ihabunek/pdf417-py/"
    },
    "split_keywords": [
        "pdf417",
        " 2d",
        " barcode",
        " generator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a4e7ff592768b4ecdd307ee66cbe8360d8158b41e9321c78a1d9114339d6705",
                "md5": "4f579395041616358e1dc2792543516d",
                "sha256": "6979bb4a8b5a17f282a54e85db335f5fa63e3c3bfa6160a9a09cd81c526194e9"
            },
            "downloads": -1,
            "filename": "pdf417gen-0.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f579395041616358e1dc2792543516d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 25328,
            "upload_time": "2024-07-04T14:24:42",
            "upload_time_iso_8601": "2024-07-04T14:24:42.906764Z",
            "url": "https://files.pythonhosted.org/packages/2a/4e/7ff592768b4ecdd307ee66cbe8360d8158b41e9321c78a1d9114339d6705/pdf417gen-0.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f4c2d82079abbd2ca93e531b3d75947b704cf21fabd96a3b6c91adcb79a3464",
                "md5": "166022d1cf386ccde73c6b811e1def4f",
                "sha256": "259d7fd43f7a6ac3ce6a49b787244001369a7166190bdbd77257d984da4149f1"
            },
            "downloads": -1,
            "filename": "pdf417gen-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "166022d1cf386ccde73c6b811e1def4f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 1786149,
            "upload_time": "2024-07-04T14:24:47",
            "upload_time_iso_8601": "2024-07-04T14:24:47.610733Z",
            "url": "https://files.pythonhosted.org/packages/8f/4c/2d82079abbd2ca93e531b3d75947b704cf21fabd96a3b6c91adcb79a3464/pdf417gen-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-04 14:24:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ihabunek",
    "github_project": "pdf417-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pdf417gen"
}
        
Elapsed time: 4.50106s