我想在Django站点中添加条形码生成,并想知道最好的库或api是什么。我的第一个偏好是可以从Python调用的东西--要么是用Python编写的,要么是我可以用ctypes/SWIG包装的C/C++库。否则,如果必须,我可以调用命令行。
我至少需要EAN和UPC符号体系。
我试过pybarcode,但图像质量太低。Elaphe看起来很有希望,但从Python解释器中我能做的只是一个QR代码-- EAN和UPC都出错了(可能是因为文档中的语法/用法不明确)。
发布于 2011-07-02 04:30:33
使用pybarcode并将条形码生成为SVG:http://packages.python.org/pyBarcode/barcode.html#creating-barcodes-as-svg
在这种情况下,图像质量没有问题。
发布于 2019-03-09 17:15:58
这个帖子很老了,但是如果其他人正在寻找这个问题的答案……与大多数类型的条形码一样,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>发布于 2016-02-04 17:17:26
reportlab可能是pybarcode的一个很好的替代品,特别是在使用它的一些其他特性时。
在Django的reportlab中有一个条形码的使用方法,对我来说效果很好。https://code.djangoproject.com/wiki/Barcodes
https://stackoverflow.com/questions/6552878
复制相似问题