LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Print Subscribe to Linux Subscribe to Newsletters
Linux & Unix > Excerpts >
Living Linux

Outputting Text

04/04/2000

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 report.ps, and then preview it, you'd type:

$ enscript -p report.ps report.txt RET
$ ghostview report.ps 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/font.map; 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




Tagged Articles

Be the first to post this article to del.icio.us

Recommended for You

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

Sign up today to receive special discounts,
product alerts, and news from O'Reilly.
Privacy Policy >
View Sample Newsletter >
  • Youtube
  • http://www.youtube.com/OreillyMedia
  • Twitter
  • Subscribe
  • View All RSS Feeds >
O'Reilly Media

800-889-8969 or 707-827-7019
Monday-Friday 7:30am-5pm PT
©2011, O'Reilly Media, Inc.
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
  • About O'Reilly
  • Academic Solutions
  • Contacts
  • Customer Service
  • Careers
  • Press Room
  • Privacy Policy
  • Terms of Service
  • Writing for O'Reilly
  • Community
  • Authors
  • Forums
  • Membership
  • Newsletters
  • RSS Feeds
  • User Groups
  • More O'Reilly Sites
  • igniteshow.com
  • makerfaire.com
  • makezine.com
  • craftzine.com
  • labs.oreilly.com
  • Partner Sites
  • PayPal Developer Zone
  • O'Reilly Insights on Forbes.com