Home / Alt manpages / pbmtolps(1)

  • pbmtolps(1)
  • User command
  • linux

Convert a PBM image to printer-ready PostScript with pbmtolps

You will convert a monochrome PBM bitmap into PostScript and check that the result is a valid output file. The command emits PostScript on standard output, so the practical pattern is to redirect it to a new file, inspect that file, and keep the original bitmap untouched. Allow about ten minutes for a small image and a first conversion.

You need a Linux shell, the netpbm package, and a readable PBM file. The installed command used for these examples is Netpbm 11.5.2. Its local manual page is dated 6 July 2019, so the version statement describes this machine rather than every Netpbm release.

1. Check the installed command and input

Confirm that the executable is available and that the input can be read. These checks do not change either file:

$ command -v pbmtolps
/usr/bin/pbmtolps
$ test -r /path/to/input.pbm && echo readable
readable

PBM means a portable bitmap: one bit per pixel, with black and white image data. If the source is PNG, JPEG or another Netpbm format, convert it to PBM with an appropriate tool first. Do not pass an arbitrary image file to pbmtolps and assume it will detect or resize it.

Checkpoint

Stop here if command -v prints nothing or the readability test fails. Fix the path or package installation through your normal system process before attempting conversion. The conversion itself normally needs no elevated privileges.

2. Choose the printer resolution

Use -dpi to state the target printer resolution in dots per inch:

$ pbmtolps -dpi=300 /path/to/input.pbm > output.ps

The option accepts the equals form shown above or whitespace in place of the equals sign:

$ pbmtolps -dpi 300 /path/to/input.pbm > output.ps

The manual says that one input pixel corresponds to one printed dot and that you must use -dpi to describe the target printer. This controls the physical size of the resulting picture, not the number of pixels in the PBM. A 600 dpi target prints the same pixel grid more compactly than a 300 dpi target.

On this installed build, omitting -dpi still produced output containing a 300 dpi scale factor. Treat that as an implementation detail of the local command, not as a safe substitute for documenting your intended printer setting. Put the explicit resolution in scripts and runbooks so a later machine cannot silently use a different default.

3. Write the PostScript without losing an existing file

Shell redirection with > truncates its destination before the program starts. If output.ps already matters, convert to a temporary name in the same directory and replace the old file only after checking the result:

$ pbmtolps -dpi=300 /path/to/input.pbm > output.ps.new
$ status=$?
$ if [ "$status" -eq 0 ]; then
>     mv -- output.ps.new output.ps
> else
>     printf 'conversion failed with status %s\n' "$status" >&2
>     rm -f -- output.ps.new
> fi

The mv runs only after a successful exit status. If the conversion fails, the old destination remains in place and the incomplete temporary file is removed. The final rm is limited to the named temporary output; do not broaden it to a directory or an unquoted wildcard.

For a new destination, the shorter command is fine:

$ pbmtolps -dpi=300 /path/to/input.pbm > output.ps
$ printf 'exit status: %s\n' "$?"
exit status: 0

4. Verify the generated file

Inspect the file type and the beginning of the output. A successful local conversion produced an Encapsulated PostScript file with a DSC level 2 header:

$ file output.ps
output.ps: PostScript document text conforming DSC level 2.0, type EPS
$ sed -n '1,8p' output.ps
%!PS-Adobe-2.0 EPSF-2.0
%%Creator: pbmtolps
%%Title: /path/to/input.pbm
%%BoundingBox: 305 395 306 396
%%EndComments
%%EndProlog
gsave

The exact title and bounding box depend on the input file and image dimensions. The useful checks are a zero exit status, a non-empty output, and a PostScript header beginning with %!PS-Adobe-2.0 EPSF-2.0. Do not judge success from a silent terminal alone: the image data is in the redirected file.

Checkpoint

Keep the PBM until the PostScript has rendered correctly in the consumer you care about. If a viewer or printer rejects the file, first check that the source really is PBM and that the chosen dpi matches the target device. Do not delete the source as a troubleshooting shortcut.

5. Use standard input when a pipeline is clearer

The PBM filename is optional, so a preceding command can write PBM data to standard output and pbmtolps can read it from standard input:

$ cat /path/to/input.pbm | pbmtolps -dpi=300 > output.ps
$ file output.ps
output.ps: PostScript document text conforming DSC level 2.0, type EPS

For a single existing file, naming the input is easier to audit. Use a pipeline when it removes a deliberate intermediate file, and remember that the output still needs the same safe handling and verification. If an upstream command fails, a shell pipeline may still run pbmtolps; for a multi-stage script, enable the shell's pipeline failure handling or check each stage explicitly.

6. Understand what pbmtolps is for

pbmtolps is a focused converter. Its output uses line operations instead of the PostScript image operator, which the manual describes as a device-dependent picture that can be imaged faster. It also keeps generated paths below 1,000 segments to avoid limits on an Apple LaserWriter and possibly other printers. Those details explain why this tool exists, but they do not make it a general image-layout or colour-management program.

If you need a more general conversion from Netpbm formats to PostScript, the manual points to pnmtops. That is a separate command with different output behaviour. Choose it deliberately rather than adding unsupported options to pbmtolps. The only tool-specific option documented here is -dpi, apart from common libnetpbm options such as -quiet.

Common failure traps

  • Wrong input format: a file ending in .pbm is not proof of its contents. Check the source with file /path/to/input.pbm and convert it properly if it is another format.
  • Unexpected physical size: one pixel is one printed dot. Re-run with the target printer's explicit dpi rather than resizing the bitmap by guesswork.
  • Destroyed output: plain > output.ps overwrites an existing destination before conversion. Use output.ps.new and the conditional mv pattern when replacement matters.
  • False confidence from exit status: status 0 confirms that the command completed, not that a particular printer will render the picture as intended. Check the header and render the file in the actual workflow.
  • Unnecessary privilege: reading a source image and writing a PostScript file in a directory you own do not require sudo. Elevated access only belongs in the separate task of installing packages or writing to a protected destination.

Done means

  • pbmtolps is available and the source is a readable PBM image.
  • An explicit target resolution was supplied with -dpi.
  • The command returned status 0 and wrote a non-empty PostScript file.
  • The output begins with the expected EPS header and has been checked in the intended viewer or printer workflow.
  • The original PBM remains available, and any existing output was protected until replacement succeeded.