Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any good pdf417 Barcode libraries for Python?

I'm looking for a good python module to generate pdf417 barcodes. Has anyone used one they liked?

Ideally I would like one with as few dependencies as possible, and one that runs on both linux and MacOSX.

like image 591
Ken Cochrane Avatar asked Aug 16 '11 14:08

Ken Cochrane


2 Answers

We recently had to approach this problem as well, and being a Python shop we wanted a Python solution. It become clear the elaphe is the project that had the potential to actually accomplish pdf 417 barcode.

However what we found was it errors by todays standards, and so we entered the hunt to fix the library. Turns out elaphe must generate an outdated form of *.eps post script that can't be interpreted by ghost script and this is where the bar code generation fails.

Well fortunately elphae uses a common library behind the scenes called Barcode Writer in Pure PostScript @ http://bwipp.terryburton.co.uk

This common backend library which has many projects in multi-languages using it to generate projects. The fix specifically for us was to fork elaphe, and correct it's *.eps file generation.

To determine what is broken in the *.eps, look at this other site that is made using postscriptbarcode, and it let's you generate the pdf417 barcode online (as well as other formats): http://www.terryburton.co.uk/barcodewriter/generator/

Once you generate a pdf417 barcode it gives you the option to download the .png, .jpg, and YES the .eps file!

Using this .eps file you can pipe it to ghost script and tweak the parameterization to get the exact pdf417 barcode you are looking for. Then take this result and integrate it into the elaphe library and actually get a pull request on that thing ....

Seems to be a bit of work, but nothing that can't be knocked out in an afternoon. It is ideal to get the elaphe library back in shape to generate these without making this enhancement.

Please note that the performance of this approach for us is a few seconds to generate this barcode due to the fact it creates the 2000 line eps file and pipes it to ghost script which generates another image file that we send back as the final barcode result. This is not as performance as code128 with reportlab.

Perhaps room for optimizations: Is pillow faster than PIL in anyway? Do we need all the parts of the eps file to generate the barcode of type pdf417? Other ways to optimize?

Anyway, great question Ken and I hope you find this to be a great answer.

like image 192
Matteius Avatar answered Oct 04 '22 21:10

Matteius


I guess the issue in elaphe reported by Matteius in 2013 has been fixed, since the issues and commit logs show updates on the pdf417 topic since then.

Anyway, there are now a few other options (got the list with either pip search elaphe or pip search pdf417) :

  • elaphe ;
  • elaphe3 (fork of elaphe tested against python3) ;
  • candybar (no documentation ? also a webservice) ;
  • pdf417gen ;
  • treepoem (about the name : barcode -> bark ode -> tree poem =D ) — edit : didn't dig the issue, but as of today generation of PDF417 seems broken.

All but pdf417gen support several types of barcodes.

Note that the documentation of bwipp (on which are based elaphe and treepoem) only mentions 5 levels of error correction (1 to 5), while pdf417gen claims to support 9 security levels (0 to 8).

like image 30
Skippy le Grand Gourou Avatar answered Oct 04 '22 21:10

Skippy le Grand Gourou