A - A - A

Linux and Printing

 
Search

Overview

After having learnt something about text editing, it seems sensible to provide a brief introduction to the subject of printing under Linux. Although word processors are available for Linux, you will still need to learn something about traditional UNIX tools like the lpr printer daemon and the power of PostScript - a language which is used to describe page layouts.

Although using the command line to print documents is not the easiest way to produce a hard copy of your documents, this approach has considerable advantages over the use of a conventional word processor like OpenOffice or Abiword because the user creates plain text files which are portable across platforms. Moreover, although BSD-derived packages like lpr are more difficult to learn about than GUI based printer management tools, the Berkeley UNIX (BSD) approach gives the user a fine-grained control over the printer.

Planning Ahead

Because of the complexity of the printer configuration process, we shall not discuss the topic in any detail. We would however, advise any user to do the following:

  • Obtain your printer's technical specifications which will usually be available from the manufacturer's web site.

  • Read through all relevant document - both HOWTOs and man pages - before doing anything.

  • Check that your printer is working from within RISC OS before attempting to configure it for Linux.

  • Do a test print using the lptest utility.

  • Edit the /etc/printcap file where necessary.

  • Ensure that Ghostscript works both with the X Windows System and through the shell.

  • Use an application like magicfilter which helps you to configure your printer.

Tip: If you have a Linux system up and running and you want to print man pages, an environmentally friendly method is to take advantage of the psnup command which forms part of the pstools package. This command allows you to decide how many man pages will be printed per page although it is dependent on the user being able to convert the requisite page to PostScript format.

A Simple Example

Assuming that you have successfully configured your printer, printing through the shell generally involves two stages:

  1. the user creates a document with an editor like Vim or Emacs which may be interlaced with formatting instructions. Such formatting instructions are typically specific to either TeX or Groff.

    A number of filters may also be applied to the file if the user intends to do things like formatting line lengths. Other examples of typical filters include Enscript and a range of magic filters which convert to PostScript on the basis of a file's initial filetype.

  2. The file is then sent to the printer by using lpr, Enscript or Ghostscript.

With regard to point two, lpr could be used to print a plain text file formatted according to personal preference. If a more complex document has been generated with either TeX or Groff which includes floating objects like tables and graphs, then one possible alternative would be to convert the file to PostScript as a prelude to printing to a PostScript printer. Groff and TeX files can for example both be converted to PostScript using Dvips - a DVI to PostScript driver. Alternatively, users without a PostScript printer can also take advantage of Ghostscript- a program which can be used as a PostScript viewer, file converter and printer driver.

So in order to make the process more meaningful, let's use a fictitious document to illustrate the process in action. Suppose we have written a letter to a friend using LaTeX - the TeX macro set. For those who are unfamiliar with LaTeX, a sample file together with formatting instructions, is listed below:

\documentclass[a4 paper,12pt]{letter}
\name{Mr A. L. User}
\address{ARMLinux Users' Group\\
Torvald's Road\\
Linuxland}
\signature{ARMLinux User}
\date{June 12, 2000}
\begin{document}
\begin{letter}{Aleph One\\
The Old Courthouse\\
Bottisham\\
Cambridge}
\opening{Dear Aleph One}
I am writing to say how pleased I am with Aleph ARMLinux. Yes it
is very different from RISC OS but it's worth perservering with.
\closing{Yours sincerely}
\end{letter}
\end{document}

You would of course create this document with your favourite editor before saving it as letter.tex. Don't forget the suffix which indicates that the file is a LaTeX source file. letter.tex would then be processed by using the latex command to create a Device-Independent or DVI file - letter.dvi - with the dvi suffix.

latex letter

You are now ready to convert letter.dvi to PostScript by using Dvips. If you are successful, you will be left with letter.ps.

dvips -o letter.ps letter.dvi

And finally, print using either lpr Enscript or Ghostscript.

lpr letter

You can also print the raw LaTeX file with the pr command although this would not be particularly appropriate in a situation where one wished to process the formatting instructions as opposed to seeing them on the page.

pr letter

Resources

There is a wealth of information on printing and related utilities under Linux.

But your first port of call should be the:

Aleph ARMLinux CD

The printing HOWTOs are available on the CD in the Docs.Html-Howto. The relevant man pages are, as always, ever useful.

PostScript

General PostScript and Ghostscript resources are available from http://www.geocities.com/SiliconValley/5682/postscript.html/. PostScript-specific information can also be found on Adobe's web site at http://www.adobe.com/print/postscript/.

Ghostscript

Ghostscript's Home Page can be found at http://www.cs.wisc.edu/~ghost/ whilst the Ghostscript Manual is available from http://www.pdflib.com/gsmanual/index.html/.

TeX

Point your browser to http://www.tug.org/in order to learn about printing TeX-related files. Similarly, http://www.sunsite.ubc.ca/Resources/Graphics/dvips/ is the link to a comprehensive manual on the DVI to PostScript driver.