Roland's homepage

My random knot in the Web

Generating barcodes with “BWIPP

Originally I looked for a Python module to generate barcodes, and I found the treepoem module. This used Pillow to create bitmaps, and I preferred to have PDF or other resolution independant formats. Looking through the README, I found that treepoem is a wrapper for bwipp. This is a set of PostScript procedures to generate barcodes.

Since I’m familiar with using PostScript, I decided to use bwipp directly.

I downloaded “” from it github releases, and unpacked it. See also the bwipp website for documentation. Then I copied the to ${HOME}/lib/ps. (That location is part of my GS_LIB environment variable.)

> cd tmp/src/
> tar xf ../
> install -m 600 ~/.local/lib/ps/

The following PostScript code generates a large (1” square) GS1 datamatrix barcode in a tightly fitting page.

%%BoundingBox: -1 0 73 72
% file:
% vim:fileencoding=ISO-8859-1:fdm=marker:ft=postscr
% Copyright © 2019 R.F. Smith <>
% Created: 2019-07-05T22:17:59+0200
% Last modified: 2020-05-10T21:16:01+0200
% Convert to PDF with the following command.
%   gs -q -sDEVICE=pdfwrite -dNOPAUSE -dNOSAFER -dAutoRotatePages=/None -dBATCH \
%   -sOutputFile=out.pdf in.eps
( runlibfile
    << /PageSize [72 72] >> setpagedevice
%%Page: 1 1

0 0 moveto
((90)591480047505) (width=1 height=1) /gs1datamatrix / findresource exec

The following command is used to convert this to a PDF file, and to the PNG file shown below.

gs -q -sDEVICE=pdfwrite -dNOPAUSE -dNOSAFER -dAutoRotatePages=/None -dBATCH \
gs -q -sDEVICE=pngmono -dNOPAUSE -dNOSAFER -dAutoRotatePages=/None -dBATCH \

This is what the barcode looks like.

Datamatrix barcode for “(90)591480047505”.

N.B: Installing BWIPP as a resource didn’t work for me. If I installed the resouces in /home/rsmith/lib/ps/Resource, ghostscript couldn’t find it with GS_LIB set to /home/rsmith/lib/ps. This seems to be in contradiction with the ghostscript website. When I set GS_LIB to /home/rsmith/lib/ps/Resource, BWIPP would work. But other postscript programs that used e.g. standard resources would not work!.

For comments, please send me an e-mail.

Related articles

←  A simple feed reader for Youtube