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

Listen Print Subscribe to Linux Subscribe to Newsletters
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

  1. Cover of Building Secure Servers with Linux
    Building Secure Servers with Linux
    Print: $44.95
  2. Cover of VMware Cookbook
    VMware Cookbook
    Print: $39.99
    Ebook: $31.99
  3. Cover of sed and awk Pocket Reference
    sed and awk Pocket Reference
    Print: $9.95
    Ebook: $7.99
  4. Cover of Apache: The Definitive Guide
    Apache: The Definitive Guide
    Print: $34.95

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com