Jump to content

Controlling print jobs in Unix with Postscript

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
Postscript is the programming language used to control the majority of printers for personal computers. It gives you more control over how a text file will appear when printed, including the typeface, whether to print in portrait or landscape, how far to indent, etc. The key commands for Unix printing are lp, lpr, lpstat, and enscript.


Using lp and lpstat:

The command to send a file to the printer in Unix is lp (lpr in some systems). It can be used for both text and binary files (such as images). To print using lp, you need to know the name of the destination printers you can use, that is, what printers the system recognizes (if a printer is not recognized, you may have to configure it manually). To do this, type:

lpstat
...In the terminal. This should show some information, including the name of the main printer.

lp -d printer_name filename
This is the standard format for the lp command. The option -d means the destination printer.


Using enscript:

enscript is the Unix command to convert a text file to PostScript automatically. You don't need to know PostScript, just this command and its options. The bare-bones format of the enscript command is:

enscript -o output-file.eps textfile
The filename after -o is the file to send the PostScript code to (the PostScript file). The extension for a PostScript file is .eps.

Other options:

-f - controls the typeface used when printing the file. The name of the typeface consists of the font name followed by a number for the size, as in Courier10 (the default).

-r - print in landscape format

-R - print in portrait format

-b - controls the heading to put on the file. The default is the filename and the date.

-F - select a font for the header text.

-i - number of characters to indent

-j - print borders around the pages

Example:

enscript -r -b "2010 Calendar" -f Monaco9 -i 5 -o calendar.eps calendar.txt

For more information on enscript's options, see the man page.


Printing PostScript files:

lp can be used for a PostScript file just like an ordinary file. It will print the output of the PostScript program, not the code itself.

Some systems (such as Mac OS X) will convert a PostScript file to a PDF when it is opened in the GUI. This makes it possible to print it without using the command line or lp.
Life's too short to be cool. Be a nerd.

#2
James.H

James.H

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 866 posts
Nice tips here, thanks DarkLord!