Home / Alt manpages / pnmtopclxl(1)

  • pnmtopclxl(1)
  • User command
  • linux

Convert PNM Images into Controlled PCL XL Print Jobs

You will turn one or more PNM images into an HP PCL XL printer stream, save it without corrupting an existing output, and set the page options that matter in practice. The examples use Netpbm 11.5.2, installed here as package version 2:11.05.02-1.1build1. Allow about fifteen minutes if the input image is ready.

You need the netpbm package, a readable PNM file, and a printer or print queue that accepts PCL XL. This guide creates a binary print stream. Do not open it in a text editor or send it to a printer until you have checked the options and destination.

1. Confirm the installed command

Start with read-only checks. No elevated privileges are needed:

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

The manual page is dated 22 March 2011, while the installed executable reports the newer library build above. The documented options and the observed commands in this guide are therefore tied to this installed Netpbm release. Check the local manual again after changing packages.

2. Generate a normal one-image stream

Use a new destination name. Standard output carries the PCL XL data, while diagnostic messages go to standard error:

$ pnmtopclxl /path/to/input.pnm > /tmp/image.pclxl
pnmtopclxl: Processing File 1, Page 1
$ test -s /tmp/image.pclxl && wc -c /tmp/image.pclxl
196 /tmp/image.pclxl

Your byte count will differ. The useful check is that the command exits successfully and the output is non-empty. A normal, non-embedded stream sets up the printer, places one image on a page and ejects the page. If the input contains multiple images, they become pages in the same order. Multiple input files are also accepted.

Do not use sudo for conversion merely because the eventual printer is managed by an administrator. Run as an ordinary user when you can read the input and write the destination.

3. Choose image resolution and page position

-dpi describes the image resolution in the generated stream, not the physical printer resolution. Its default is 300 dpi. The offsets are distances in inches from the left and top of the page to the image's upper-left corner:

$ pnmtopclxl -dpi=300 -xoffs=0.5 -yoffs=0.75 /path/to/input.pnm > /tmp/image-positioned.pclxl

The input can have its own borders, so the visible picture may start further in than these coordinates. If you use the documented centring option, the offsets are meaningless and should be left out:

$ pnmtopclxl -center /path/to/input.pnm > /tmp/image-centred.pclxl

Checkpoint: decide whether the page layout is controlled by centring or by explicit offsets. Do not combine them while troubleshooting a placement problem.

4. Set paper, tray, copies and duplexing

These options add printer instructions to the stream. The default paper format is letter, so specify the format when the job must use a different size:

$ pnmtopclxl -format=a4 -feeder=2 -copies=2 -duplex=vertical \
    /path/to/input.pnm > /tmp/image-a4-duplex.pclxl

Supported paper keywords include letter, legal, a3, a4, a5, a6, exec, ledger, several envelope names, and Japanese postcard formats. -feeder selects the media source number understood by the printer. -copies asks the printer to make that many copies, so check the requested value before releasing a job.

With -duplex=vertical, both page fronts use the same left edge. -duplex=horizontal is the usual top-edge arrangement. These settings describe the printer stream; the actual printer must support the requested media source and duplex mode.

5. Avoid accidental colour output

If the input is PPM, pnmtopclxl generates an RGB stream and warns by default. A monochrome laser printer may reject it, and transmitting a colour stream can take roughly three times as long as an equivalent grayscale stream. Treat the warning as a useful decision point, not as noise.

For a grayscale job, convert the PPM through ppmtopgm before passing it to pnmtopclxl:

$ ppmtopgm /path/to/input.ppm | pnmtopclxl /dev/stdin > /tmp/image-gray.pclxl
pnmtopclxl: Processing File 1, Page 1

This pipeline leaves the original PPM unchanged. If the PNM is already grayscale, you can generate the stream directly. If colour is intentional and the printer accepts it, -colorok suppresses the warning:

$ pnmtopclxl -colorok /path/to/colour.ppm > /tmp/image-colour.pclxl

The warning-suppression option does not convert anything. It only says that you accept the colour output.

6. Replace an output file safely

Shell redirection with > truncates its destination before the converter runs. That can destroy a useful print stream if the input path is wrong or conversion fails. Write a temporary file first, then replace the destination only after the command and size check succeed:

$ pnmtopclxl -format=a4 /path/to/input.pnm > /tmp/image.pclxl.new
$ test -s /tmp/image.pclxl.new
$ mv /tmp/image.pclxl.new /path/to/image.pclxl

mv is the state-changing step. It needs write permission on the destination directory and replaces an existing file of that name. If the conversion fails, keep the old output and remove only the incomplete temporary file:

$ rm /tmp/image.pclxl.new

That removal is irreversible, so confirm the path before running it. No command in this workflow needs root unless your chosen input or output directory is deliberately restricted. If access is denied, fix the directory ownership or use an approved destination rather than making a printer stream world-writable.

7. Use embedded output only inside another PCL XL job

-embedded changes the contract: it emits only the image instructions, not a complete printer stream with page setup and page ejects. It is useful when another program is assembling a PCL XL page, but it is not a standalone file to send to a printer.

$ pnmtopclxl -embedded /path/to/one-image.pnm > /tmp/image-fragment.pclxl

This mode accepts only a single image. If the input file contains several images, later images are ignored. Options that control the surrounding printer stream, including -xoffs and -feeder, are invalid with -embedded. Keep this output separate from complete jobs so it cannot be mistaken for something a queue can print by itself.

8. Add job setup only when you own the commands

-jobsetup=filename copies arbitrary PJL job-setup commands to the beginning of the output stream. The program does not inspect or validate them. A malformed or inappropriate file can make the printer complain, so inspect it and keep it under controlled permissions before using it:

$ ls -l /path/to/trusted-jobsetup.pjl
$ pnmtopclxl -jobsetup=/path/to/trusted-jobsetup.pjl /path/to/input.pnm > /tmp/image-with-setup.pclxl

This is not a general configuration file for pnmtopclxl; it is raw content copied into the print stream. Do not use it with downloaded or unreviewed input.

Done means

  • The installed command and Netpbm version were checked.
  • The PCL XL stream is non-empty and was written to a deliberate destination.
  • Paper, tray, copies, duplexing and image placement match the job you intend to release.
  • Grayscale input was used for a monochrome job, or colour output was explicitly accepted with the warning-suppression option.
  • Existing output was protected by writing a temporary file before replacement.
  • -embedded and -jobsetup were used only for their specialised, trusted workflows.