Home / Alt manpages / pktopbm(1)

  • pktopbm(1)
  • User command
  • linux

Convert a PK Font to PBM Files with pktopbm

You have a TeX packed (PK) font and need to look at the actual glyphs, not trust that the metrics are right. pktopbm turns that PK file into one PBM bitmap per character, with predictable names you can inspect with other Netpbm tools. This guide uses the installed Netpbm 11.5.2 command. Allow about fifteen minutes if you already have a PK file and know which character range it contains.

Prerequisites are a readable PK font, the netpbm package, and a writable output directory. The conversion itself normally needs no elevated privileges. Do not reach for sudo just because the font came from a system directory; copy it to a working directory or grant your account read access instead.

1. Check the installed command

Confirm the executable and package version before building a script around it. This is a read-only checkpoint:

$ command -v pktopbm
/usr/bin/pktopbm
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ pktopbm --version
pktopbm: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
pktopbm: Built from source dated 2024-03-31 09:09:47
pktopbm: Built by Debian
pktopbm: Use 'man pktopbm' for help.

The version output carries build details too, so wording differs across distributions. The part worth trusting is that the command resolves and identifies the Netpbm library it is using. The local manual is dated 15 September 2023 and documents the command as it exists here.

2. Prepare a separate output directory

pktopbm writes PBM output files and never edits the PK input, but shell redirection and output names can still overwrite files if you point it at an existing destination. Start in a new directory:

$ mkdir -p ~/tmp/pktopbm-output
$ cd ~/tmp/pktopbm-output
$ cp --preserve=all /path/to/font.pk ./font.pk
$ test -r font.pk && echo 'input is readable'
input is readable

Replace /path/to/font.pk with your real file. Copying is optional, but it leaves you a working copy to keep once you start deleting generated bitmaps. The command accepts - as a filename for standard input or output, but a named file is easier to check while you are still learning the workflow.

Safety boundary

Do not send output into a directory containing valuable PBM files unless you have already checked the names pktopbm will use. If you need to abandon this setup, remove only the copied input and the empty directory you made, not the original font.

3. Convert a font using its recorded bitmap sizes

Run the input PK file followed by one or more PBM output filenames:

$ pktopbm font.pk glyph-001.pbm glyph-002.pbm

The first output file gets the first character selected from the font, the second gets the next one, and so on. Width and height default to whatever each bitmap actually is in the font: pktopbm does not resize every glyph onto a common canvas unless you tell it to.

Check the files immediately:

$ ls -lh glyph-001.pbm glyph-002.pbm
$ file glyph-001.pbm glyph-002.pbm
glyph-001.pbm: Netpbm image data, bitmap, 8 x 12
glyph-002.pbm: Netpbm image data, bitmap, 7 x 12

Your dimensions and file wording depend on the font. No progress message on a successful run is normal. Check the exit status with $? in a script, and keep the original PK file around until you have actually looked at the PBM images.

4. Select the character number for the first output

Use -character followed by a numeric code point when the first output filename should start at a particular character. This asks for output beginning at character 65:

$ pktopbm -character 65 font.pk glyph-065.pbm glyph-066.pbm
$ file glyph-065.pbm glyph-066.pbm
glyph-065.pbm: Netpbm image data, bitmap, 8 x 12
glyph-066.pbm: Netpbm image data, bitmap, 8 x 12

There is no output for code points below the number you supply. The option is handy when you already have a selected range of filenames, but it will not conjure missing characters into existence. Use an exact number from the font's encoding or your conversion plan, never a guessed letter label.

Some installed documentation shows the short spelling -c in the synopsis while the options section names -character. The current binary accepts -c too, but the long spelling reads better in new scripts:

$ pktopbm -c 65 font.pk glyph-065.pbm

Do not confuse this option with changing the glyph bitmap itself. It only changes which character the first output file represents.

5. Put glyphs on a common canvas

Use -x for a fixed width, -y for a fixed height, or both. Whatever you set applies to every bitmap that invocation produces:

$ pktopbm -x 16 -y 16 -character 65 font.pk glyph-065.pbm glyph-066.pbm
$ file glyph-065.pbm glyph-066.pbm
glyph-065.pbm: Netpbm image data, bitmap, 16 x 16
glyph-066.pbm: Netpbm image data, bitmap, 16 x 16

Once either dimension is specified, pktopbm uses the horizontal and vertical offsets stored in the PK file to relocate the bitmap, with the base point placed in the lower-left corner. If the canvas you asked for is too small, content at the top or right gets truncated. That is real data loss in the generated PBM files, so pick dimensions from the font metrics rather than reaching for 16 by 16 out of habit.

For a fixed width but font-defined height, use only -x; for a fixed height but font-defined width, use only -y. Verify the resulting dimensions with file: a file existing on disk is not proof the canvas was actually large enough.

6. Diagnose a failed conversion

A missing input is reported before any useful conversion can happen:

$ pktopbm /path/to/missing.pk glyph.pbm
pktopbm: Unable to open file '/path/to/missing.pk' for reading. fopen() returns errno 2 (No such file or directory)

Check the path and permissions without changing anything:

$ ls -l /path/to/font.pk
$ test -r /path/to/font.pk && echo readable

An invalid or non-PK input produces a bad-file diagnostic such as bad PK file (pre command missing). Check that the file is really the packed font itself, not a TeX font metric file, a compressed archive, or something whose name merely ends in .pk: the suffix does not validate the contents.

If the dimensions look surprising, rerun first without -x or -y to see the font's recorded sizes. If you need a common canvas, add one dimension at a time and check the output. If glyphs look clipped, choose a larger canvas and regenerate into a new directory; the existing PBM files are not repaired in place by a later command.

Done means

  • You confirmed the pktopbm executable is the expected Netpbm 11.5.2 build, and the PK input is readable.
  • Each requested output file is a non-empty PBM image, confirmed with file.
  • The first output character is controlled with an explicit -character value when needed.
  • Fixed -x and -y dimensions were chosen deliberately and checked for clipping.
  • The original PK font is still there, and generated files landed in a directory you reviewed.