Power Printing With MagicFilter

Here's a program to take the work out of printing—just like magic.
Power Demonstration

Now it's time for some tests. First, try printing a normal text file from your prompt; something short, like:

lpr /etc/group

Your printer should print the file without the staircase effect. Assuming no problems here, try printing a PostScript (.ps) file. Next, try a graphics file like a .gif or .jpeg. If you have one handy, try printing a .dvi file. All these files should produce perfect output. Finally, try printing a binary file like /bin/sync. You should not get any output from your printer, and, if you're running sendmail, smail or other mail agent, you should get an almost immediate e-mail from bin@your.localhost explaining why your file could not be printed. If you're not running a mailer, your $ prompt will return, and you will get no output from your printer. MagicFilter does not display error messages on the console.

At this point, it's worthwhile to print a listing of the actual filter scripts for your printer. You'll notice that it's an interpreted script with MagicFilter as the interpreter. It's laid out in three vertical columns. Column one is the offset from the file's beginning, column two is the string of characters searched for and column three is the facility for dealing with each type of file. Reading down the column, you can see all the different types of files that MagicFilter can handle and how it handles them, as well as the ones it can't. Note the pipe and fpipe methods in column three. That method's output is fed back into MagicFilter for a second or subsequent pass. This is necessary in the case of .dvi files, for example. First dvips runs on the .dvi file, and the resulting temporary PostScript file is fed back into MagicFilter where ghostscript then performs the actual printing—pretty slick.


This popular e-mailer requires a little tweaking to work properly. If you leave Pine's default printing mechanism set to lpr, you may find that e-mails of more than one page will lose the last 2 or 3 lines of text on some printers. This is due to the fact that some printers, Canon ink jets for one, can't print more than 63 lines per page, and lpr thinks they ought to have 66 lines per page. To fix this, create a short script called print, containing these two lines:

pr $1 | lpr

Put this script in your home directory, or somewhere in your path, then install it as Pine's printing command. From Pine's main menu, select as follows: S (setup), P (printers), then arrow down to “Personally selected print command”. Set “Printer List” to /dev/lp1 (or whatever your printer device is named) and your print command (on that same line) to ~/print. To make these changes, enter C-N (change, name) and then C again (change command). Save your changes when prompted.

This printing setup will run your e-mail through the pr utility for formatting before spooling to print. This is kind of neat, because your pages of output will have a date/time stamp and page number on the top of each page. You can modify pr's behavior with command line switches to produce the appearance you wish (see man(1) pr).


You should be able to print from Netscape without any tweaks at all. To test it, fire up Netscape and load a challenging document. From the File menu, select Print and observe the dialog that opens up. From the top of the dialog, verify that the “Printer” button is pushed, that your “Print Command” is lpr and that the rest of the print settings make sense for your printer and paper. Then, press the “Print” button. Figure 1 shows how this should look.

Figure 1. Netscape Dialog

You should get a printout of exactly what's on your browser screen, graphics and all. Of course, this assumes you have a graphics-capable printer and that you built MagicFilter with at least ghostscript support. Netscape defaults are stored in a file called ~/.Netscape/preferences. You can check that file to make sure your print command is lpr and adjust it, if necessary.

You can even use Netscape as a sort of kludgy word processor. From the File Menu, select “New Document -> Blank”. The Netscape Editor will open up with a blank screen, ready to copy. This editor is geared toward HTML; it's great for writing WWW pages, but for producing letters, etc., it leaves a lot to be desired. With Netscape's editor, what you see on the screen usually does not exactly match the printer output.