Home / Alt manpages / pbmupc(1)

  • pbmupc(1)
  • User command
  • linux

Create a UPC Barcode PBM Image with pbmupc

Feed pbmupc three digits from a real product code and it draws you a scannable UPC barcode as a PBM bitmap, no design software required. You will check the dimensions come out right, and optionally make a scaled copy for printing or display. The examples use Netpbm 11.5.2, packaged here as netpbm 2:11.05.02-1.1build1. Allow about ten minutes if Netpbm is already installed.

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 the manual itself uses for Heineken. This workflow only writes image files: no barcode service is contacted, nothing on the system changes, and it normally needs no elevated privileges.

1. Check the installed command

Confirm which executable you are running and note the package version. These are all 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

More build information may show up on your installation than this. The point that matters is that the command comes from Netpbm 11.5.2: if yours reports something else, check the local manual before trusting the exact diagnostics below.

Checkpoint

A readable /usr/bin/pbmupc and a Netpbm version worth recording alongside the image you generate.

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. What comes out is a raw PBM bitmap, not a text preview, documented at 230 bits wide by 175 bits high. You can check the header without dumping the binary pixels themselves:

$ head -n 2 heineken-upc.pbm
P4
230 175

P4 marks a raw PBM image. Binary data begins right after the dimensions, so a command like head can print unreadable characters if you read past those first two lines.

Shell redirection opens the destination before pbmupc even runs. If heineken-upc.pbm already holds something useful, pick a new name or back it up first, a failed run can otherwise leave a truncated file in its place.

3. Validate the fields before troubleshooting the image

The command will not accept arbitrary text. The first argument must be exactly one digit, and the manufacturer and product arguments must each be 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 signal worth acting on here. Do not try to fix this by adding punctuation or spaces inside a field: keep each field a separate, digit-only shell word. If your source system shows a UPC with separators, strip them out and split the value into the three fields pbmupc actually wants.

Checkpoint

A successful run creates a non-empty file whose header reads P4, 230, 175. A validation error means the input shape is wrong, not that PBM output is somehow unsupported.

4. Choose the alternate display style

Use -s2 when you want the product type digit placed higher and the checksum digit left off the printed text. The barcode data comes from the same three numeric arguments either way:

$ 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 the way the manual describes. Style -s2 changes the presentation, not the output format or the nominal canvas size. If something downstream expects the usual printed digits, stick with the default unless you have a specific reason not to.

5. Scale a copy for a different physical size

pbmupc has no width or height option of its own. The documented route is to pass its PBM output through pamscale, keeping the original barcode intact and writing the scaled result somewhere new:

$ 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

Scaling is a separate Netpbm operation. With PBM input, this installed pamscale promotes the result to PGM so it can blend pixels, hence the .pgm suffix above. It does not touch the source file. Check the installed pamscale(1) manual for other scaling modes or non-integer dimensions, and do not assume a display pixel matches a printer's physical size. For a barcode specifically, keep edges sharp and test the printed result with the actual scanner you plan to use.

If the scaling command fails, keep heineken-upc.pbm and read the error before retrying: do not replace the original with an unverified scaled file. To undo an unwanted replacement, delete only the new output after double-checking the path, or restore the original from backup. Deleting a file is irreversible the moment it leaves 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 that may need sudo, but generating a PBM in a directory you own does not.

If file reports a different format or dimensions, look at the first two header lines and make sure you are inspecting the file you just wrote:

$ 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 still rejects the image, try a Netpbm-aware viewer or conversion tool instead. The output is a genuine PBM bitmap, and some image applications simply have weak support for portable bitmap variants. A viewer error is not proof the UPC digits were encoded wrong.

Done means

  • Command confirmed. pbmupc is the expected Netpbm executable, and its local version is recorded.
  • Fields validated. The type, manufacturer and product fields have the required 1, 5 and 5 digit shapes.
  • Output verified. The generated file is a non-empty raw PBM with a P4 header and 230 by 175 dimensions.
  • Style chosen deliberately. You picked -s1 or -s2 knowing what each printed layout changes.
  • Original preserved. Any resize went through pamscale into a separate file, leaving the original barcode available for recovery.