Home / Alt manpages / pf2afm(1)

  • pf2afm(1)
  • User command
  • linux

Create an AFM File from a Type 1 Font with pf2afm

You will turn a PostScript Type 1 font in PFB or PFA form into an Adobe Font Metrics file, without changing the source font. The output is written beside the input as .afm. Allow about ten minutes if the font is already available. This guide uses Ghostscript 10.02.1, installed here as package version 10.02.1~dfsg1-0ubuntu7.9.

You need the ghostscript package, a readable PFB or PFA file, and write permission in the directory where you want the AFM file. The conversion itself normally needs no elevated privileges. Do not use sudo merely because the command belongs to Ghostscript.

1. Check the installed command and font

Confirm which executable will run, then inspect the input. Substitute the path to your own font for the example path:

$ command -v pf2afm
/usr/bin/pf2afm
$ dpkg-query -W -f='${Package} ${Version}\n' ghostscript
ghostscript 10.02.1~dfsg1-0ubuntu7.9
$ test -r /path/to/ExampleFont.pfb && echo 'font is readable'
font is readable

The command accepts one font name. It can be a name ending in .pfb or .pfa, or a stem without that extension. With no extension, the installed Ghostscript script tries .pfb first and then .pfa.

Checkpoint: the input test must print font is readable. If it does not, fix the path or permissions before running the converter. A permission change on a shared or protected directory is an administrator decision; do not broaden permissions as a quick fix.

2. Generate the AFM beside the font

Run the command with the font path as its only argument:

$ pf2afm /path/to/ExampleFont.pfb
pfm file not found -- ignored

The PFM line is a warning, not a failed conversion. PFM is optional. When it is present, Ghostscript can use it for extra font parameters and kerning information. The result for this input is /path/to/ExampleFont.afm, not a second .pfb suffix. The same naming rule applies when the input is a PFA file or a stem without an extension.

On a font with a matching PFM file, the warning is normally absent. The PFM must use the same stem, such as ExampleFont.pfm. The installed script also looks in a pfm subdirectory when the direct file is not present.

Verify the file before using it:

$ test -s /path/to/ExampleFont.afm && echo 'AFM exists and is non-empty'
AFM exists and is non-empty
$ sed -n '1,8p' /path/to/ExampleFont.afm
StartFontMetrics 2.0
Comment AFM Generated by Ghostscript/pf2afm
FontName ExampleFont
FullName Example Font
FamilyName Example
Weight Regular
ItalicAngle 0.0
IsFixedPitch false

The exact font names and metrics depend on the input. The useful checks are the StartFontMetrics header and a non-empty file. AFM is text, so a header check is safe; do not assume that a successful-looking file has the right metrics for a damaged or unusual font.

3. Protect an existing AFM file

Before running the conversion, check whether the destination already exists:

$ test -e /path/to/ExampleFont.afm && echo 'destination already exists' || echo 'destination is free'
destination is free

Warning

pf2afm refuses to generate a destination that already exists. On this installed version it prints Resulting file exists and still exits with status 0. The same zero status is used when neither a PFA nor PFB input can be found. Do not use the exit status alone as proof that conversion worked.

Keep an old AFM by choosing a different output directory or moving it out of the way after making a deliberate backup. For example, this preserves the original and converts a copied font in a new temporary directory:

$ workdir=$(mktemp -d /tmp/pf2afm.XXXXXX)
$ cp --preserve=mode,timestamps /path/to/ExampleFont.pfb "$workdir/"
$ pf2afm "$workdir/ExampleFont.pfb"
pfm file not found -- ignored
$ test -s "$workdir/ExampleFont.afm" && echo 'conversion verified in staging directory'
conversion verified in staging directory
$ cp --preserve=mode,timestamps "$workdir/ExampleFont.afm" /path/to/ExampleFont.afm.new
$ mv /path/to/ExampleFont.afm.new /path/to/ExampleFont.afm

The final mv replaces the destination only after the new AFM has been checked. If the conversion or check fails, leave the .new file alone for inspection and keep the old AFM. Remove the temporary directory later using your normal temporary-file housekeeping; its contents are not needed by Ghostscript.

4. Diagnose a conversion that appears successful

If the command says Neither pfa nor pfb found, check the exact stem, case and directory. A missing input does not necessarily produce a non-zero status on this version, so check the expected AFM explicitly:

$ ls -l /path/to/ExampleFont.pfb /path/to/ExampleFont.pfa 2>/dev/null
$ test -s /path/to/ExampleFont.afm && echo 'usable output found' || echo 'no usable AFM output'
no usable AFM output

If the command says Resulting file exists, do not delete the old file automatically. Compare it with the AFM you need, or use the staging pattern above. If the output directory is not writable, run test -w /path/to and choose a directory you own. Elevation is only appropriate when an administrator has intentionally assigned this conversion to a protected system font directory.

For a font whose metrics matter to a publishing or typesetting workflow, inspect the generated AFM and test it in the application that will consume it. pf2afm extracts metrics; it does not repair a malformed font, install the font, or update an application's font cache.

Done means

  • pf2afm comes from the expected Ghostscript installation and the PFB or PFA input is readable.
  • The AFM has the input stem and is in the expected directory.
  • The file is non-empty and begins with StartFontMetrics.
  • A missing PFM was treated as an optional warning, not confused with a missing font.
  • An existing AFM was preserved, and the generated file was checked before replacement.
  • The original PFB or PFA remains untouched and the font was not installed as a side effect.