Convert a PFB Font to PFA with pfbtopfa
pfbtopfa turns a binary PostScript Type 1 font in PFB form into a plain-text PFA copy, leaving the original untouched. The examples use the pfbtopfa wrapper supplied by Ghostscript 10.02.1, from Debian package version 10.02.1~dfsg1-0ubuntu7.9. Allow about ten minutes, plus time to locate a font you are permitted to convert.
The route
Jump straight to the step you need, or tick off Done means at the end.
This is a file conversion, not a font installation. You need Ghostscript, a readable .pfb file, and write access to the destination directory. The commands below are ordinary user commands: there is no reason to use sudo unless the input sits in a protected directory and you have separately decided that copying it is safe.
1. Check the installed tool
Confirm the executable and package version before relying on the examples below. This is read-only:
$ command -v pfbtopfa
/usr/bin/pfbtopfa
$ dpkg-query -W -f='${Package} ${Version}\n' ghostscript
ghostscript 10.02.1~dfsg1-0ubuntu7.9
$ gs --version
10.02.1
The installed manual describes the interface as pfbtopfa input.pfb [output.pfa]. The wrapper calls gs(1) behind the scenes. It is not a general-purpose font editor, and it does not install the result in a system font directory.
Checkpoint
You know the exact input path, the Ghostscript version, and a destination directory where you can create a new file.
2. Inspect the input without changing it
Use the real path in place of /path/to/font.pfb. Check that it exists, is readable, and is a regular file:
$ input='/path/to/font.pfb'
$ ls -l -- "$input"
$ test -f "$input" && test -r "$input" && echo 'input is a readable regular file'
input is a readable regular file
- Keep the source extension accurate in your notes. A file name alone does not prove the contents are a valid PFB font, but it makes later checks easier.
- Never edit the PFB file in place. It may be the only copy you have, and a failed conversion has no undo for changes made beforehand.
3. Convert to a named output
Choose a new destination explicitly. The second argument is optional, but naming it makes scripts and reviews clearer:
$ output='/tmp/font-copy.pfa'
$ pfbtopfa "$input" "$output"
$ printf 'exit status: %s\n' "$?"
exit status: 0
The wrapper accepts exactly one or two positional file names; there is no separate option parser. Quote both variables, because paths may contain spaces or shell metacharacters. The command writes the output file only: it does not modify the PFB source.
Safety warning
If $output already exists, the converter may replace it. Check first when the destination matters:
$ test ! -e "$output" && echo 'destination is unused'
destination is unused
If it is an existing useful file, pick another name. If you deliberately need to replace it, back it up first:
$ cp --preserve=all -- "$output" "$output.bak"
$ pfbtopfa "$input" "$output"
$ cmp -- "$output" "$output.bak" || true
That last comparison normally reports that the new output differs from the backup, which is expected. To recover the old destination, remove the new file and move the backup back into place: rm -- "$output" && mv -- "$output.bak" "$output". Do not run that recovery command blindly; verify both paths first.
4. Verify the PFA result
A zero exit status only says the wrapper completed. Confirm the output exists, is non-empty, and looks like PostScript text:
$ test -s "$output" && echo 'output is non-empty'
output is non-empty
$ file -- "$output"
/tmp/font-copy.pfa: PostScript Type 1 font text (font-name 1.00)
$ head -n 1 -- "$output"
%!PS-AdobeFont-1.0: font-name 1.00
The exact font name and version depend on the input. A PFA normally begins with a PostScript font header and contains readable text. Do not treat a matching file extension as proof of success: if file reports generic data or the first line is missing, keep the PFB and investigate rather than installing the result.
You can also ask Ghostscript to read the generated font without writing anything:
$ gs -q -dBATCH -dNOPAUSE -sDEVICE=nullpage "$output"
$ printf 'Ghostscript validation status: %s\n' "$?"
Ghostscript validation status: 0
This only exercises Ghostscript's parser. It does not prove every application will accept the font, that its metadata is desirable, or that the font licence permits redistribution.
5. Understand the default destination
When you omit the second argument, pfbtopfa derives a PFA name from the input file's base name and asks Ghostscript to write it in the current working directory, not the input's directory. For a font already in your working directory:
$ pfbtopfa /work/font.pfb
$ test -s ./font.pfa && echo 'derived output exists'
derived output exists
Check the derived path before running this form: an existing .pfa with the same base name is a possible overwrite target. The explicit-output form is safer for repeatable jobs, temporary conversions, and batch scripts. With Ghostscript's default file-access restrictions, an absolute explicit output path is also less surprising than relying on the current directory.
6. Diagnose failures without losing the source
If the command cannot open the input, check the path and permissions:
$ ls -l -- "$input"
$ test -r "$input" && echo readable || echo 'not readable'
$ ls -ld -- "$(dirname -- "$output")"
- Fix permissions properly. If the destination cannot be created, choose a directory you own or fix its permissions through your normal system-administration process. Do not make a whole directory world-writable just to complete a conversion.
- Isolate the fault. If Ghostscript prints an unrecoverable error, preserve the original PFB, remove only an incomplete output after checking its path, and try a known-good font to separate an input problem from an installation problem.
- Keep both files until verified. Hold on to the PFB and the PFA until the new copy has passed the header, size,
file, and Ghostscript checks. Removing the source is irreversible and is not required for conversion.
Done means
- Tool confirmed:
pfbtopfaand Ghostscript 10.02.1 are installed and identified. - Source untouched: the original PFB remains unchanged and readable.
- Output exists: a separately named PFA is non-empty and has a PostScript Type 1 header.
- Output verified:
filerecognises the result and Ghostscript reads it with exit status 0. - Nothing else touched: no system font directory, service, or package configuration was changed.