ARCHIVED: Unix printing using enscript, dvips, and psduplex
On this page:
Introduction
A number of print commands are available in Unix. For
information about the most basic, see ARCHIVED: In Unix, how do I print files and list or remove print jobs? Following is
information about the commands dvips
(which converts
DVI files to PostScript and prints them),
enscript
(which converts text files to Postscript and
prints them), and psduplex
, which makes a file print on
both sides of the page.
Using dvips
The dvips
command in Unix takes a DVI file, produced by
TeX or LaTeX, and turns it into a PostScript
file. It then attempts to print the file on the default printer,
unless told otherwise.
You can send the output of the dvips
command to a file
using the -o
switch. For example, to convert the DVI file
myfile.dvi
into a PostScript file named
newfile.ps
, you would enter:
dvips -o newfile.ps myfile.dvi
Although the output of the dvips
command can be
redirected, its input cannot be taken from a pipe, but instead, must
be redirected from a file. For example, you could enter:
dvips -f < myfile.dvi | 2up | psduplex | lpr -Pps99
This would convert myfile.dvi
to PostScript, send it to
the 2up command for side-by-side printing, filter through
psduplex
for double-sided printing, and use the BSD print
command to send the output to the printer named ps99
(which is
assumed to be PostScript- and double-sided-compatible).
Using enscript
The enscript
command in Unix changes a text file to
PostScript format and then sends it to the printer. The
general format is:
enscript [switches] textfilename
Replace textfilename
with the name of the file you want
to convert and print. The [switches]
are optional
settings, as follows:
-h |
Suppress printing banner pages
|
-P (uppercase P) |
Specify a printer (BSD-compatible
systems)
|
-d |
Specify a printer (System V systems)
|
-2 |
Print two columns per page |
-r |
Rotate the output 90 degrees |
-G |
Print "gaudy" headers, with large page numbers
and filenames
|
-l (lowercase L) |
Simulate a 66-line-per-page line
printer
|
-p (lowercase p) |
Direct output to standard output
or to a file
|
-2
and -r
options to
produce 2up style documents, with two pages per sheet in
landscape orientation.
For more information about enscript
, read its
man page by entering:
man enscript
Printing a file beginning with the last page and ending with the first page
Two Unix commands, psselect
and psrev
, can
reverse the output of a PostScript file.
In the following examples, replace printer
with the
network-connected PostScript printer of your choice (e.g.,
ps99
) and filename
with the name of your
file.
To use psselect
on a BSD system, at the Unix prompt,
enter:
enscript -p - filename | psselect -r | lpr -Pprinter
To use psselect
on a System V system, enter:
enscript -p - filename | psselect -r | lp -d printer
To use psrev
on a BSD system, at the Unix prompt, enter:
enscript -p - filename | psrev | lpr -Pprinter
To use psrev
on a System V system, enter:
enscript -p - filename | psrev | lp -d printer
The enscript command feeds to the standard output,
psrev
or psselect
reverses the order of the
PostScript file, and then this is fed to the printer via
lpr or lp.
Using psduplex
The psduplex
command in Unix makes a file print on both
sides of the paper. It will work only with printers that support
double-sided (i.e., duplex) printing.
The psduplex
command accepts PostScript format
input, and should be the last filter used before the
print command.
A single switch, -tumble
, causes files printed in
landscape mode to be rotated along the short side of the paper to keep
the text upright. Normally, the rotation is done along the long side
of the page.
For example, on a system using BSD-compatible printing, to
take the output of the enscript command converting a text
file named myfile.txt
and print it double-sided on a
compatible printer named ps99
, you would enter at the
Unix prompt:
enscript -p- myfile.txt | psduplex | lpr -Pps99 -h
To print the same document in tumbled landscape mode, you would enter:
enscript -2rh -p- myfile.txt | psduplex -tumble | lpr -Pps99 -h
Be sure that the printer you're using can handle double-sided printing
before you use psduplex
.
Because psduplex
is actually just an executable
Perl script, you can easily install it on your own system
by copying the text in between the lines into a file:
#!/usr/local/bin/perl -s # psduplex - insert PostScript code to set and unset duplexmode for this job # # usage: psduplex [-tumble], default "edge" # # Steve Kinzler, kinzler@cs.indiana.edu, October 1991 $_ = <>; unless (/^%!/) { # not PostScript, pass through as is print; while (<>) { print; } exit; } print; while (<>) { last unless /^\s*%/; print; } print "statusdict begin\n\ttrue setduplexmode\n"; print "\ttrue settumble\n" if $tumble; print "end\n"; print; while (<>) { print; } print "statusdict begin\n\tfalse setduplexmode\n"; print "\tfalse settumble\n" if $tumble; print "end\n";
Examples
Here are some examples of printing files with various combinations
of the lpr, enscript
, 2up,
dvips
, and psduplex
commands. Not all
utilities are available on all Unix systems.
In all examples, replace printername
with the defined
name of the printer. Also, in examples using the lpr
commands, you could use the equivalent lp commands.
- On a BSD-compatible system, convert and print a text file without
a banner page:
enscript -Pprintername -h myfile.txt
- Make a PostScript file of the text file
myfile.txt
and save it asmyfile.ps
:enscript -pmyfile.ps myfile.txt
- Redirect the output of
enscript
as input for another command:enscript -2rG -p- myfile.txt | psduplex | lpr -Pprintername -h
This will convert
myfile.txt
into a two-column, rotated PostScript file with a large header, send it through the psduplex filter to print on both sides of the paper, and finally print the result without a banner page. - Print a text file, one page per sheet, one-sided:
lpr -Pprintername -h filename.txt
- Print a text file, two pages per sheet, one-sided, gaudy headers,
landscape mode:
enscript -Pprintername -2rGh filename.txt
or:enscript -hl -p- filename.txt | 2up | lpr -Pprintername -h
- Print a text file as in step 5, but on both sides of the paper:
enscript -lh filename.txt | psduplex | lpr -Pprintername -h
or:enscript -hl -p- filename.txt | 2up | psduplex | lpr -Pprintername -h
- Print a text file as in step 5, but on both sides of the
paper, with you owning the job but getting a header page:
enscript -2rG -p- filename.txt | psduplex | lpr -Pprintername
- Print as in step 5, but with you not owning the
job (i.e., can't remove it from the queue), without getting a header page:
enscript -2rGh -Pprintername filename.txt
- Print a text file on both sides of the paper, with four or
eight pages per side of one sheet, saving paper:
enscript -hl -p- filename.txt | 4up | psduplex | lpr -Pprintername -h enscript -hl -p- filename.txt | 8up | psduplex | lpr -Pprintername -h
- Print a PostScript (PS) file, one page per sheet, one-sided:
lpr -Pprintername -h filename.ps
- Print a PS file, two pages per sheet, landscape, one-sided:
2up filename.ps | lpr -Pprintername -h
- Print a compressed PS file as in step 10:
zcat filename.ps.Z | lpr -Pprintername -h
- Print a compressed PS file as in step 11:
zcat filename.ps.Z | 2up | lpr -Pprintername -h
- Print a PS file as in step 10, but double-sided:
cat filename.ps | psduplex | lpr -Pprintername -h
- Print a PS file as in step 11, but double-sided:
2up filename.ps | psduplex | lpr -Pprintername -h
- Produce a PS file from a DVI file:
dvips -o outfilename.ps filename.dvi
- Print a DVI file one-sided, one page per sheet:
dvips -f < filename.dvi | lpr -Pprintername -h
- Print as in step 17, but double-sided:
dvips -f < filename.dvi | psduplex | lpr -Pprintername -h
- Print as in step 17, but two pages per sheet:
dvips -f < filename.dvi | 2up | lpr -Pprintername -h
You can also use
4up
or8up
if you want. - Print as in step 18, but two pages per sheet:
dvips -f < filename.dvi | 2up | psduplex | lpr -Pprintername -h
At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.
Related documents
This is document abbp in the Knowledge Base.
Last modified on 2018-01-18 08:51:26.