Running Linux, 5th Edition - Matthias Kalle Dalheimer [270]
* * *
nenscript and enscript
The nenscript utility, now often called enscript, is a flexible filter that provides good formatted output for PostScript printers, even from ASCII text files. It isn't a basic Linux utility, but it is included in most Linux distributions and can be retrieved from the usual Linux FTP sites.
* * *
Tip
Although nenscript and enscript create PostScript output, they can still be used if you have a non-PostScript printer. As described later in this chapter, a properly configured Linux print queue automatically converts PostScript to the formats required by non-PostScript printers.
* * *
Suppose you are printing out a C program and want line numbering and a printout on green-striped fanfold paper (not the same format you'd want when printing those graphics you downloaded from the Internet on your nifty PostScript printer). You need to have the program processed, and then insert the line numbers in front of the lines. The solution is to process the file through a filter such as the enscript utility. After doing its own processing, enscript passes the file to lpr for spooling and printing to your trusty tractor-feed printer (named here):
$ enscript -C -B -L54 -Pdino -M Letter myprogram.c
The enscript filter numbers each line of the file passed through it when you specify the -C option. (Earlier versions of enscript used -N rather than -C for line numbering.) The -B option suppresses the usual header information from being printed on each page, and the -L54 option specifies formatting at 54 lines per page. The enscript filter just passes the -Pdino option through to lpr, which interprets it and directs the output to dino's print spool for printing. The -M Letter option specifies you want a printout on letter-size paper. (Depending on compile-time options, enscript may default to European A4 paper.)
When called on the command line, enscript automatically passes output to lpr unless you specify standard output by supplying the -p option. You don't need to pipe or redirect enscript output to lpr explicitly.
Suppose you are going to print a lot of program listings today. For convenience, you can set an environment variable for enscript to specially process and print your listings each time:
$ export ENSCRIPT=" -C -B -L54 -Pdino -M Letter"
Now, to print your listing correctly, all you need enter is:
$ enscript myprogram.c
enscript optionally sends output to a file, which is often useful for preparing PostScript files on Linux hosts that don't actually have a PostScript printer available. For example, to convert a text file to a PostScript file, formatted for two-column printing on the standard European A4 paper format in 6-point Courier font, you would type:
$ enscript -2 -f Courier6 -M A4 -p document.ps document.txt
The -2 option overrides the one-column default, and the -f Courier6 option overrides the 7-point Courier default for two-column output. (The one-column default is Courier 10; enscript always uses Courier font when converting plain text into PostScript, unless told to do otherwise via -f.) The -M A4 option specifies A4 paper size. (To learn what options are available, type enscript - -list-media.) The -p option specifies that the output should be stored to document.ps, and the filename specified with no option is the input to enscript. If no filename had been specified, enscript would have taken standard input as the filename.
As another example, to print the enscript manual page as basic text on a PostScript printer, enter:
$ man
enscript | col -b | enscript
The man command retrieves the manual page and formats it for text display. The col -b command strips the backspace instructions for highlighting and underlining, leaving plain text that is piped to the enscript filter. This turns the plain text into simple PostScript with some "pretty printing" that applies headers, footers, page numbering, and the like. Finally,