Contents Previous Next

13.2 Printing from command line

From command line (= Terminal, Console or Shell) you can print files using the "lp" command:

lp -d <printername> <filename>

Depending on the Linux version also the command "lpr" may be used:

lpr -P <printername> <filename>

Instead of <printername> enter the short name of the printer configuration, as is shown in the TurboPrint control center. The default short name for the first TurboPrint printer is " tp0 ".

If you want to print a postscript file named "test.ps" to the printer " tp0 ", enter

lp -d tp0 test.ps

Another way is to use lp is to put it at the end of a "pipe" - the output of another command is used as input from lp. This is useful if a file is formatted or converted first before it is sent to the printer.

Example:

a2ps --output=- textfile.txt | lp -d tp0

An ASCII file is converted to a postscript file using the a2ps command. The output is printed by lpr.

For more information on lpr see its man page, which you can view using

man lpr

Specifying print options

Print options can be added to the „lp“ command

lp -d <printername> -o <option>=<value>

e.g.

lp -d tp0 -o Resolution=600x600dpi <filename>

There are standard options that can be used for all printers and printer specific options.

Some standard options are:

landscape print in landscape format (page rotated by 90 degrees)

sides=two-sided-long-edge duplex printing

sides=two-sided-short-edge duplex (pages bound on short edge)

number-up=2 print 2 (4,16) pages on one sheet

Further options can be found on the CUPS HTML online help (see link below).

The following command lists all options that are available for a printer

lpoptions -p <printername> -l

an.

Formatting ASCII documents

To print ASCII text files in a certain layout, you can call a2ps or enscript directly. Here are some examples:

a2ps --portrait --borders=0 --columns=1 --no-header --printer=tp0 myfile.txt



enscript --portrait --columns=1 --no-header --printer=tp0 myfile.txt

prints just the text - no borders, one column, no headers

a2ps --landscape --borders=1 --columns=2 --printer=tp0 myfile.txt



enscript --landscape --borders --columns=2 --printer=tp0 myfile.txt

prints the text in landscape orientation with borders, two columns per page with headers (filename, page numbers).

For more information on a2ps and enscript see the man pages (man a2ps, man enscript) .

Printing Images

Images e.g. in JPG format can be printed directly from command line. Positioning and scaling is done by the CUPS printing system. By default images are rotated if in landscape format and are printed in original size (i.e. the size stored in the image file). If image size exceeds page size several pages are printed.

Image size (in percent of page size) can be specified from command line, e.g.

lp -d tp0 -o scaling=50 filename.jpg

Further options can be found in the CUPS HTML online help - see link below.

If you want to position images exactly or if you want to print several images on one page you can use the application " Libre Office Draw" - see also section " 13.1.3 LibreOffice / OpenOffice" in this chapter.

Which file types can be printed?

Many common file types like postscript documents, plain ASCII files or JPG images can be printed directly from command line. If a file format is not supported directly (like some image formats) it must be converted first.

Responsible for correctly discerning the file type is the CUPS printing system - see HTML online help in the CUPS web frontend

http://localhost:631/


Contents Previous Next