oreilly.comSafari Books Online.Conferences.


Living Linux

Outputting Text


As we discussed last week, the next few columns in this series will describe some of the available tools and applications for doing word processor-like things with Linux.

GNU Enscript is a tool that takes plain text as input and writes PostScript output, doing any number of formatting changes in between. It's great for quickly making nice output of a plain text file -- you can use it to do things like output text in a font of your choosing, or paginate text with graphical headers at the top of each page.

By default, enscript paginates its input, outputs it in a 10-point Courier font, and puts a simple header at the top of each page containing the filename, date and time, and page number in bold. Use the -B option to omit this header.

If you have a PostScript printer connected to your system as the default printer, enscript spools its output right to the printer. You can verify this on your system by looking at the enscript configuration file, /etc/enscript.cfg. The line DefaultOutputMethod: printer specifies that output is spooled directly to the printer; stdout instead of printer sends to the standard output instead.

Most Linux installations nowadays have print filters set up so that PostScript spooled for printing is automatically converted to a format the printer understands (if your system doesn't have this set up for some reason, convert the PostScript to a format recognized by your printer with the gs tool).

For example, to convert the file report.txt to PostScript with default formatting, and spool the output right to the printer, you'd type:

$ enscript report.txt RET

You can write the output to a file instead with the -p option, which takes the name of the file to output as an argument. This is useful for previewing the output before you print it -- view it on the screen with a PostScript viewer application like ghostview.

To write the file report.txt to a PostScript file, and then preview it, you'd type:

$ enscript -p report.txt RET
$ ghostview RET

Printing text in a font

To output text in a particular font, give the name of the font to use as a quoted argument to the -f option.

Specify both the font family and size in points: give the capitalized name of the font family (with hyphens to indicate spaces between words) followed by the the size in points. For example, Courier14 outputs text in the Courier font at 14 points, and Times-Roman12.2 outputs text in the Times Roman font at 12.2 points. A list of available font names are in the file /usr/share/enscript/afm/; the enscript man page describes how to use additional fonts that might be installed on your system.

To print the contents of the text file report.txt in the Helvetica font at 12 points, type:

$ enscript -B -f "Helvetica12" report.txt RET

When headers are used, they're normally output in 10-point Courier Bold; to specify a different font for the text in the header, give its name as an argument to the -F option.

To print the contents of the text file report.txt with text set in 10-point Times Roman and header text set in 18-point Times Bold, type:

$ enscript -f "Times-Roman10" -F "Times-Bold18" report.txt RET


Pages: 1, 2, 3

Next Pagearrow

Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: