Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate barcodes in Django site

Tags:

django

barcode

I want to add barcode generation in a Django site and wonder what the best library or api would be. My first preference is something callable from Python - either written in Python or a C/C++ lib that I can wrap with ctypes/SWIG. Otherwise I can call out to the command line if must be.

I need at least EAN and UPC symbologies.

I've tried pybarcode but the image quality is too low. And Elaphe looks promising but from the Python interpreter all I could make was a QR Code -- EAN and UPC errored out (maybe because the syntax/usage was unclear from the documentation).

like image 933
ram1 Avatar asked Jul 01 '11 20:07

ram1


2 Answers

Use pybarcode and generate the barcode as SVG: http://packages.python.org/pyBarcode/barcode.html#creating-barcodes-as-svg

No problem of image quality in that case.

like image 65
zengr Avatar answered Sep 23 '22 22:09

zengr


This thread is quite old, but in case anyone else is looking for an answer to this... code39 is a font, as are most types of barcode. You can simply use google fonts: https://fonts.google.com/specimen/Libre+Barcode+39+Extended+Text?selection.family=Libre+Barcode+39+Extended+Text

Aside from that option, you could host static files, one solution could be this project on github:

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

In that project all you need are the files associated with the size you want, and the code39_all.css file. The rest you could delete, if you like.

For your reference, I'm using both here:

{% 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>
like image 28
Aaron Goodrich Avatar answered Sep 21 '22 22:09

Aaron Goodrich