Printer Adjustments

The Linux printer setup dialog can install zillions of drivers from the printer database and print nice test pages to verify the driver works, but what if it doesn't work? What if the margins are way off (or even only a little off, but you need to print labels or forms with exact alginment)? I recently replaced my ancient HP LaserJet 6L (which died after many years of service) with a Brother HL-2040, and the default alignment was pretty awful with the recommended driver, so I tried to recall how to use the alignmargins script I once used many years ago, and rediscovered how confusing the instructions were. What follows is a much more verbose set of instructions that I know I'll need if I ever need to do this again, and hopefully they will help someone else as well.

Squirreled away in the obscure Open Printing Downloads web site are two files which are handy for tweaking your printer driver. The align.ps file is a postscript file that prints obscure looking gibberish your eyes will never be able to focus on, yet is useful for printer alignment. The alignmargins file is a perl script to help a little in applying the information you dig up using the align.ps printouts. There is also some description of how to use them in the CUPS Documentation page at the linuxprinting.org site.

To use these files, put them both in the same directory, then run the alignmargins script as root. Every time you run the script (and you will run it a lot), it prints a copy of the align.ps file to the printer you select.

The first copy of the file you get will be almost totally useless, but you can read the instructions that print with the other gibberish and realize you have no idea what it says. In any case, after generating the printout, the script will ask you for a bunch of numbers. This first time through, you want to tell it 0 (zero) for all the values.

The script will edit the /etc/cups/ppd/printer-name.ppd file and add a section at the end to tweak the margin definitions. By filling in all zeroes for the margin tweaking values, you will be able to run the script again and get a printout showing exactly how the page winds up when all the margin settings are zeroed out. This is the printout you'll use to make some measurements.

For general paranoia, I always restart the cups system service after each run of the alignmargins script. This may be too much work, but I don't know if it will re-read the modified file unless I do that, and since I already have a root terminal running, it is simple enough to type /etc/init.d/cups restart

Anyway, now that you have the new printout based on all zero margins, it is time to get the most accurate ruler you can find and measure the H and V values. There are arrows labeled H and V on the printout, but they can't show the actual length you need to measure because your printer probably cannot print all the way to the physical edge of the paper. The values you want to measure are the length in inches from the physical edge of the paper to the vertical line on the left (H) and the physical bottom of the paper to the horizontal line on the bottom (V). These values will be close to one inch, but the exact difference is the important part to get as accurately as possible.

Once you have measured H and V, the instructions printed near the top of the page give the formulae for computing x and y from the H and V values (expressed in inches). In my case, the formulae are:

x = (1 - H) * 1200.0, y = (V - 1) * 600.0

The actual numbers probably depend on the resolution of the printer.

The alignmargins script has been sitting around waiting for input while you've been doing all this measuring and computing, so now you can provide some new numbers. The 1st 4 numbers the script asks for are ml, mb, mr, mt and we still don't know those, so type in 0 for them again, but you can provide it with the x and y values you just computed. If you measured accurately, you souldn't need to ever change x and y again, you will always feed the script those same values for x and y.

Now you can run alignmargins one more time. This time the printout generated will use the x and y values computed above, and the 4 truncated arrows drawn at the 4 corners of the printout should, if you extend the lines into the margin with a ruler and a pencil wind up with the point of the arrow hitting the physical corner of the page.

At this point, you are ready to read off the ml, mb, mr, mt value, which you get by examining the funny looking printout. There are numbers and tick marks along the edge of the inner rotated rectangle that appears on the page. The edges of the rectangle are clipped somewhere as it runs into the margin. The numbers you want to read off for each edge is the number where the clip happens. Once again, you want to read these as accurately as possible. Maybe get out a magnifying glass and a ruler to estimate the exact fractional position of the place where the margins were clipped. The number you pick off the left margin is ml, the bottom margin is mb, the right margin is mr and the top margin is mt.

Plug these new values in for the 1st 4 numbers, and the same values for x and y you computed above, and you should now have your .ppd file tweaked properly to print correctly.

Note that if you run alignmargins again, it will still look just as screwy as always. Nothing much happens to improve your eye's ability to focus on it, even with the printer fully adjusted. You can probably go back to the system printer config dialog and print a better looking test page now, with no clipping of anything around the edges, so the normal printer test page test may improve.

Page last modified Tue Feb 24 11:56:27 2009