Printing via LPT1 on a Linux box

Up March/05, printscreen added 8/10

Printing on Linux is accomplished with the most wildly complicated set of utilities imaginable. And -- no matter what else -- it will assume you have an inkjet or laser printer, and want everything in Postscript format.

I don't. I have a dot-matrix printer which will probably last another 100 years, and I print nearly everything in plain text format. The information below shows variously how to make some changes to allow printing directly to an LPT port (device PRN: in DOS), how to shift all the printing to a Windows box (much better utilities) via SAMBA, and how to change some file formats to plain text -- including pdf.

1: Set up a 'print' command

It is just a matter of using 'cat' to send a file to 'lp0', Keep this in /usr/local/bin/ and make it executable by all.


#!/bin/sh
# /usr/local/bin/print
# 9/99 script for printing from console
        [ "x$1" = "x" ] && {
        echo "Usage: print {file}";
        exit;
        }
        cat $1 > /dev/lp0

To print a local file type print {filename}

This information can be incorporated directly into Lynx and Pine.

For Pine it requires the following lines in the systemwide /etc/pine.conf file ...

# Your default printer selection
printer=/usr/local/bin/print -
# List of special print commands
personal-print-command=
# Which category default print command is in
personal-print-category=3

For Lynx the following line is required in the systemwide /etc/lynx.cfg file ...

PRINTER:use Local Printer:cat %s | /usr/local/bin/print - :TRUE:66

2: Printing Man Pages

Man pages are strangly formatted and can't just be printed after viewing. The following will remove all the back-strikes which otherwise make the file unreadable.


#!/bin/sh
# this is a pipe  /usr/local/bin/printman {manpage}
# print a man page to plain text, in home directory
echo "usage: printman {manpage} > ~/{same name file}"
echo
echo ... printing manpage $1, hold on ...
man $1 | col -b > ~/$1

This just writes a file of the same name as the manpage you were looking at. For example, if you typed man ls to get information on ls, then printman ls will write the file ls in your home directory. To print this file type print ls.

3: Printing pdf files

If pdftotext is available, the following can be used to print a pdf file after conversion to html..


#! /bin/sh
# /usr/local/bin/printpdf, cleanup of pdf file, HTML-ize, and print
pdftotext -raw $1 foo
cat foo | sed -e 's/[[:cntrl:]]//g' | sed -e 's/^[[:space:]]*$//'  \
	| sed -e '/^ *[[:digit:]*] *$/d' \
	| sed -e 's/-$//g' \
	| fold -s \
	| sed -e 's/^$/<P>/' \
        | uniq > $1.htm
lynx -dump $1.htm | print -
rm -f foo

4: Using SAMBA and a networked printer

The SAMBA suit of files allows networked communication with Windows machines. I use a Windows 3.11 computer without a monitor or keyboard to do networked printing. It is set up to print from its Epson LQ-570 dot matrix printer, and will spool 10 files. If the power goes off the computer simply reboots into operation by itself -- unlike some later Windows Operating Systems. But later Windows boxes could also be used for the same purpose.

The Windows machine has to be set up to 'export' its printer, under some name -- I use 'Epson'-- and of course be connected to the network. Below are a set of utilities and inserts into rc files to allow printing via the network.

Printing a local file uses the command printfile -- which goes as follows (the remote Windows box happens to be known as 'Dragon') ...


#!/bin/sh
# /usr/local/bin/printfile
# 9/99 script for printing to network printer 
smbclient '\\Dragon\EPSON' -PNc 'print -'   > /dev/null
smbclient '\\Dragon\EPSON' -PNc 'print /usr/local/bin/ff' > /dev/null

The second line sends a formfeed. The file ff is created by inserting a 0Ch -- a formfeed -- into ff.

Do that with with cat > ff; ^L; ^D.

To print a local file type printfile {filename}

This information can be incorporated directly into Lynx and Pine.

For Pine it requires the following lines in the systemwide /etc/pine.conf file ...

# Your default printer selection
printer=/usr/local/bin/printfile
# List of special print commands
personal-print-command=
# Which category default print command is in
personal-print-category=3

For Lynx the following line is required in the systemwide /etc/lynx.cfg file ...

PRINTER:use Local Printer:cat %s | /usr/local/bin/printfile:TRUE:66

5: Printing a mousegrab from Linux

Linux allows mouse grabs, where text which will be located in a mouse buffer after highlighting. This can be printed.


#!/bin/sh
# 1/06 script for printing a mouse grab to network printer
# /usr/local/bin/printscreen
# File /usr/local/bin/cont-d is control-D -- end of data
#      make that with "edit cont-d; cont-v Cont-D; save"
#### requires and additional  and 
# see also /usr/local/bin/printmail
 echo ""
 echo " ... do a mouse paste -- then  and  ..."
 echo "ready..."
 cat - /usr/local/bin/cont-d > /dev/lp0
	

[logo]


Website Provider: Outflux.net, www.Outflux.net
URL:http://jnocook.net/geek/printing.htm