Create a UPC Barcode PBM Image with pbmupc
You will generate a Universal Product Code (UPC) bitmap as a PBM file, check that it has the expected dimensions, and optionally make a scaled copy for printing or display. The examples use the installed Netpbm 11.5.2 command, packaged here as netpbm 2:11.05.02-1.1build1. Allow about ten minutes if Netpbm is already installed.
The route
Jump straight to the step you need, or tick off Done means at the end.
You need a shell and three pieces of UPC data: one product type digit, a five digit manufacturer code, and a five digit product code. The example 0 72890 00011 is the code shown by the manual for Heineken. This workflow only creates image files. It does not contact a barcode service or alter system configuration, and it normally needs no elevated privileges.
1. Check the installed command
Confirm which executable is being used and record the local package version. These are read-only checks:
$ command -v pbmupc
/usr/bin/pbmupc
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ pbmupc --version
pbmupc: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
The version output includes more build information on this installation. The important point is that the command is from Netpbm 11.5.2. If your package reports another release, recheck the local manual before relying on exact diagnostics.
Checkpoint
You have a readable /usr/bin/pbmupc and a Netpbm version to record with the generated image.
2. Generate the default UPC style
Pass the three numeric fields as separate arguments and redirect standard output to a new file:
$ pbmupc 0 72890 00011 > heineken-upc.pbm
$ file heineken-upc.pbm
heineken-upc.pbm: Netpbm image data, size = 230 x 175, rawbits, bitmap
The default is style -s1. The generated file is a raw PBM bitmap, not a text preview. Its documented size is 230 bits wide by 175 bits high. You can inspect the portable bitmap header without dumping the binary pixels:
$ head -n 2 heineken-upc.pbm
P4
230 175
P4 identifies a raw PBM image. The binary data begins after the dimensions, so commands such as head may display unreadable characters if you read beyond those first two lines.
Shell redirection opens the destination before pbmupc runs. If heineken-upc.pbm already contains something useful, use a new name or make a backup before running the command. A failed run can otherwise leave a truncated file.
3. Validate the UPC fields before troubleshooting the image
The command does not accept arbitrary text. The first argument must be exactly one digit, and the manufacturer and product arguments must each contain exactly five digits:
$ pbmupc 0 7289 00011 > invalid.pbm
pbmupc: type code must be one digit, and
manufacturer and product codes must be five digits
A non-zero exit status is the useful signal here. Do not try to repair this by adding punctuation or spaces inside a field. Keep the fields as separate, digit-only shell words. If your source system displays a UPC with separators, remove those separators and split the value according to the three fields required by pbmupc.
Checkpoint
A successful run creates a non-empty file whose header says P4, 230, and 175. A validation error means the input shape is wrong, not that PBM output is unsupported.
4. Choose the alternate display style
Use -s2 when you want the product type digit placed higher and the checksum digit omitted from the printed text. The barcode data is still generated from the same three numeric arguments:
$ pbmupc -s2 0 72890 00011 > heineken-upc-s2.pbm
$ file heineken-upc-s2.pbm
heineken-upc-s2.pbm: Netpbm image data, size = 230 x 175, rawbits, bitmap
Style -s1 is the default and shows the product type and checksum in the layout described by the manual. Style -s2 changes the presentation, not the output format or the nominal canvas size. If a downstream process expects the usual printed digits, use the default unless you have a reason to choose -s2.
5. Scale a copy for a different physical size
pbmupc does not take a width or height option. The documented workflow is to pass its PBM output through pamscale. Keep the original barcode and write the scaled result to a separate file:
$ pamscale -xscale 2 -yscale 2 heineken-upc.pbm > heineken-upc-2x.pgm
$ file heineken-upc-2x.pgm
heineken-upc-2x.pgm: Netpbm image data, size = 460 x 350, rawbits, greymap
The scale command is a separate Netpbm operation. With PBM input, this installed pamscale promotes the result to PGM so it can perform pixel mixing. Name the output with a .pgm suffix, as shown. It does not change the source file. Check the installed pamscale(1) manual if you need a different scaling mode or non-integer dimensions; do not assume that a display pixel size is the same as a printer's physical size. For a barcode, preserve sharp edges and test the printed result with the scanner you intend to use.
If the scaled command fails, keep heineken-upc.pbm and inspect the error before retrying. Do not replace the original with an unverified scaled file. To recover from an unwanted replacement, delete only the new output after checking the exact path, or restore the original from your backup. Deleting a file is irreversible once it has left your trash or backup system.
6. Diagnose common failures
If command -v pbmupc prints nothing, the executable is not on your PATH. Check the package through your normal distribution tools. Installing packages is an administrative action and may require sudo; generating a PBM in a directory you own does not.
If file reports a different format or dimensions, inspect the first two header lines and check that you are examining the file just written:
$ test -s heineken-upc.pbm && echo non-empty
non-empty
$ head -n 2 heineken-upc.pbm
P4
230 175
If those checks pass but a viewer rejects the image, try a Netpbm-aware viewer or conversion tool. The output is a PBM bitmap, and some image applications have limited support for portable bitmap variants. Do not treat a viewer error as proof that the UPC digits were encoded incorrectly.
Done means
pbmupcis the expected Netpbm executable and its local version is recorded.- The type, manufacturer, and product fields have the required 1, 5, and 5 digit shapes.
- The generated file is a non-empty raw PBM with a
P4header and 230 by 175 dimensions. - You selected
-s1or-s2deliberately, knowing what each printed layout changes. - Any resize was made with
pamscaleinto a separate file, leaving the original barcode available for recovery.