【问题标题】:Generate barcodes in Django site在 Django 站点中生成条形码
【发布时间】:2011-09-27 00:41:26
【问题描述】:

我想在 Django 站点中添加条码生成功能,想知道最好的库或 api 是什么。我的第一个偏好是可以从 Python 调用的东西——用 Python 或 C/C++ 库编写,我可以用 ctypes/SWIG 包装。否则,如果必须,我可以调用命令行。

我至少需要 EAN 和 UPC 符号。

我试过 pybarcode 但图像质量太低了。 Elaphe 看起来很有希望,但从 Python 解释器中我只能制作一个 QR 码——EAN 和 UPC 出错(可能是因为文档中的语法/用法不清楚)。

【问题讨论】:

    标签: django barcode


    【解决方案1】:

    使用 pybarcode 并将条形码生成为 SVG:http://packages.python.org/pyBarcode/barcode.html#creating-barcodes-as-svg

    在这种情况下图像质量没有问题。

    【讨论】:

    • 完美,我会这样做,然后将 svg 导出为 png,因为 ie
    【解决方案2】:

    这个线程已经很老了,但如果其他人正在寻找这个问题的答案...... code39 是一种字体,大多数类型的条形码也是如此。您可以简单地使用谷歌字体: https://fonts.google.com/specimen/Libre+Barcode+39+Extended+Text?selection.family=Libre+Barcode+39+Extended+Text

    除了该选项,您还可以托管静态文件,一种解决方案可能是 github 上的这个项目:

    https://github.com/Holger-Will/code-39-font

    在该项目中,您只需要与所需大小相关的文件和 code39_all.css 文件。其余的你可以删除,如果你喜欢。

    供您参考,我在这里使用两者:

    {% load staticfiles %}
    {% load static %}
    <html>
      <head>
        <link href="https://fonts.googleapis.com/css?family=Libre+Barcode+39+Extended+Text" rel="stylesheet">
        <link rel="stylesheet" href="{% static 'code-39-font-master/code39_all.css' %}"/>
      </head>   
      <body>
        <style>
    
            body {
                font-family: 'Libre Barcode 39 Extended Text', cursive;
                font-size: 48px;
            }
        </style>
          <div>I'm just a code39 google font</div>
          <div><class="code_39_S">I'm generated with static files!</div>
    
      </body>
    </html>
    

    【讨论】:

    • 好悲痛,让它变得容易。谢谢。
    【解决方案3】:

    reportlab 可能是 pybarcode 的一个很好的替代品,尤其是在使用它的一些其他功能时。

    在带有reportlab 的Django 中有一个关于条形码的方法,对我来说效果很好。 https://code.djangoproject.com/wiki/Barcodes

    【讨论】:

    • 你能从链接中添加一些内容吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2019-12-17
    相关资源
    最近更新 更多