Re: Printing system in Solaris9

From: Richard L. Hamilton (Richard.L.Hamilton_at_mindwarp.smart.net)
Date: 02/07/04


Date: Sat, 07 Feb 2004 12:44:18 -0000

In article <pan.2004.02.07.11.39.57.957302@dseichter.de>,
        Daniel Seichter <daniel@dseichter.de> writes:
> Hello,
>
> can anyone tell me, if I can use another printer type than postscript
> under solaris9?

Yes.

You want to know how? That's a _long_ story, and I'm half asleep.

Text printers that you only send text to are easy enough.

If you want to be able to send graphics to a non-postscript printer,
probably the best move is to check whether ghostscript has a driver
for the printer you want - if it does, get it, configure it (used
to be a nuisance, maybe it's gotten easier), compile it, install it,
write a script that calls ghostscript to convert postscript to the
printer's native type, and write and install a filter definition
that uses that script to convert from postscript to a type you make
up corresponding to the printer model. Then create a printer that
only takes your made-up type as input; that will force all output to
it through the filter.

That's the overview; please ask someone else for the details, but first go
search for ghostscript documentation and read it, and read the lpfilter
and lpadmin man pages.

Just as an example (which I won't explain, too bad...), here's my filter
definition and the script it calls. As a clarification, the particular
ghostscript driver I used for that printer was at least at the time
distributed separately from ghostscript.

== /etc/lp/fd/epsonc80 ========= cut here ================================
Input types: postscript
Output types: epsonc80
Printer types: epsonc80
Filter type: fast
Command: /usr/local/bin/epsonc80
Options: INPUT * = -T*
Options: MODES dpi\=\([0-9a-z]*\) = -q \1
Options: MODES media\=\(.*\) = -m \1
Options: MODES papersize\=\(.*\) = -p \1
Options: MODES dithertype\=\(.*\) = -d \1
Options: MODES imagetype\=\(.*\) = -i \1
Options: MODES colortype\=\(.*\) = -c \1
== /usr/local/bin/epsonc80====== cut here ================================
#! /bin/ksh

# configuration - change to reflect location of interpreter
GS="/opt/ghostscript/bin/gs"

# shouldn't need to change these
GSCMD="${GS} -q -sOutputFile=- -sDEVICE=stp -dNOPAUSE"
MODEL=escp2-c80 # only model supported in this script for now
                  # option verification would get much more complicated
                  # if multiple models were supported

# following for error reporting only
PROGRAM="$(basename "${0}")"

# initialization, to avoid inadvertently picking up an environment variable
COLOR=
RESOLUTION=
IMAGETYPE=
DITHER=
INKTYPE=

# defaults - could change consistent with subsequent sanity checks
# QUALITY=1440x1440hq2
QUALITY=360sw
MEDIATYPE=Plain
DEFAULT_INKTYPE=CMYK # or RGB as a usually lesser alternative
DEFAULT_DITHER=Adaptive
DEFAULT_IMAGETYPE=2
DEFAULT_COLOR=1
STP_PAPERSIZE=Letter
GS_PAPERSIZE="-sPAPERSIZE=letter"
INPUT_TYPE=PS

function lperror {
   print -u2 -r - "UX:lp: ${PROGRAM} filter: ${1}"
   exit 127
}

function init_printer {
   case "${MODEL}" in
   escp2-c80) echo "\00\00\00\033\01@EJL 1284.4\n@EJL \n\033@\c";;
   *) lperror "unsupported model ${MODEL}";;
   esac
}
function usage {
   lperror \
      "usage: ${PROGRAM} [-q quality] [-m mediatype] [-p papersize] [-d dithertype] [ -i imagetype] [-c color] [-T input_type]"
}

#
# "main"
#
# Supported arguments are:
# -q quality -m mediatype -p papersize -d dither -i imagetype -c color
# -T input_type (simple aka ascii, pdf, postscript or PS)
#
# Some of those may actually be expanded to two values: one for ghostscript
# and one for the driver. This happens with papersize and quality for now.
#

while getopts q:m:p:d:i:c:T: OPTION
do
   case "${OPTION}" in
   q) QUALITY="${OPTARG}";;
   m) MEDIATYPE="${OPTARG}";;
   p) STP_PAPERSIZE="${OPTARG}";;
   d) DITHER="${OPTARG}";;
   i) IMAGETYPE="${OPTARG}";;
   c) COLOR="${OPTARG}";;
   T) INPUT_TYPE="${OPTARG}";;
   ?) usage;;
   esac
done
shift $(($OPTIND - 1))
if [ $# -ne 0 ]; then
   usage
fi

init_printer

case "${INPUT_TYPE}" in
pdf|postscript|PS) # fall through to let ghostscript handle these
   ;;
*) if cat; then # pass all others transparently
      exit 0
   else
      lperror "error writing to printer"
   fi
   ;;
esac

# Allow some additional quality values as simplified cases which will be
# expanded to the highest equivalent supported quality value. Single
# numbers should equate to NxN qualities, i.e. 360 should be 360swuni.
# As a special accomodation, 300 or 300x300 will be rounded up to 360,
# 600 or 600x600 will be rounded up to 720x720, and 1200 or 1200x1200 will
# be rounded up to 1440. This is because those are common resolutions with
# laser printers, and someone might get muddled and use one of those when
# all they want is a given quality of output rather than an exact resolution.

ORIGINAL_QUALITY="${QUALITY}"
case "${QUALITY}" in
360x180) QUALITY=360x180sw;;
300|300x300) QUALITY=360swuni;;
360|360x360) QUALITY=360swuni;;
720x360) QUALITY=720x360swuni;;
600|600x600) QUALITY=720hq2;;
720|720x720) QUALITY=720hq2;;
1440x720) QUALITY=1440x720hq;;
2880x720) QUALITY=2880x720swuni;;
1200|1200x1200) QUALITY=1440x1440hq2;;
1440|1440x1440) QUALITY=1440x1440hq2;;
2880x1440) QUALITY=2880x1440sw;;
esac

# we also need to tell ghostscript the resolution, so here is where we
# determine the resolution corresponding to the quality
case "${QUALITY}" in
360x180sw) RESOLUTION=360x180;;
360sw) RESOLUTION=360x360;;
360swuni) RESOLUTION=360x360;;
# 360hq) RESOLUTION=360x360;;
# 360hquni) RESOLUTION=360x360;;
720x360sw) RESOLUTION=720x360;;
720x360swuni) RESOLUTION=720x360;;
720sw) RESOLUTION=720x720;;
720swuni) RESOLUTION=720x720;;
720hq) RESOLUTION=720x720;;
720hquni) RESOLUTION=720x720;;
720hq2) RESOLUTION=720x720;;
1440x720sw) RESOLUTION=1440x720;;
1440x720swuni) RESOLUTION=1440x720;;
1440x720hq) RESOLUTION=1440x720;;
2880x720sw) RESOLUTION=2880x720;;
2880x720swuni) RESOLUTION=2880x720;;
1440x1440sw) RESOLUTION=1440x1440;;
1440x1440hq2) RESOLUTION=1440x1440;;
2880x1440sw) RESOLUTION=2880x1440;;
*) lperror "unsupported dpi or quality ${ORIGINAL_QUALITY}";;
esac

# put mediatype vs papersize checks here

# allow some variants of dither values
# less mischief here, so unrecognized will default to something reasonable

case "${DITHER}" in
[Aa][Dd][Aa][Pp][Tt][Ii][Vv][Ee]) DITHER=Adaptive;;
[Oo][Rr][Dd][Ee][Rr][Ee][Dd]) DITHER=Ordered;;
[Ff][Aa][Ss][Tt]) DITHER=Fast;;
[Vv][Ee][Rr][Yy][Ff][Aa][Ss][Tt]) DITHER=VeryFast;;
[Ff][Ll][Oo][Yy][Dd]) DITHER=Floyd;;
[Ff][Ll][Oo][Yy][Dd]-[Ss][Tt][Ee][Ii][Nn][Bb][Ee][Rr][Gg]) DITHER=Floyd;;
*) DITHER="${DEFAULT_DITHER}";;
esac

# ditto for inktype values
case "${INKTYPE}" in
[Cc][Mm][Yy][Kk]) INKTYPE=CMYK;;
[Rr][Gg][Bb]) INKTYPE=RGB;;
*) INKTYPE="${DEFAULT_INKTYPE}";;
esac

# ... and color values
case "${COLOR}" in
0|[Gg][Rr][AaEe][Yy][Ss][Cc][Aa][Ll][Ee]) COLOR=0;;
1|[Cc][Oo][Ll][Oo][Rr]) COLOR=1;;
2|[Bb][Ww]|[Bb][Ll][Aa][Cc][Kk][-+_][Ww][Hh][Ii][Tt][Ee]) COLOR=2;;
*) COLOR="${DEFAULT_COLOR}";;
esac

# ... and imagetype values
case "${IMAGETYPE}" in
0|[Ll][Ii][Nn][Ee]|[Ll][Ii][Nn][Ee][Aa][Rr][Tt]) IMAGETYPE=0;;
1|[Ss][Oo][Ll][Ii][Dd]) IMAGETYPE=1;;
2|[Pp][Hh][Oo][Tt][oo]) IMAGETYPE=2;;
*) IMAGETYPE="${DEFAULT_IMAGETYPE}";;
esac

# standardize STP_PAPERSIZE and set related GS_PAPERSIZE
ORIGINAL_STP_PAPERSIZE="${STP_PAPERSIZE}"
case "${STP_PAPERSIZE}" in
[Ll][Ee][Gg][Aa][Ll])
   STP_PAPERSIZE=Legal
   GS_PAPERSIZE=-sPAPERSIZE=legal
   ;;
[Ll][Ee][Tt][Tt][Ee][Rr])
   STP_PAPERSIZE=Letter
   GS_PAPERSIZE="-sPAPERSIZE=letter"
   ;;
[Aa]4)
   STP_PAPERSIZE=A4
   GS_PAPERSIZE="-sPAPERSIZE=a4"
   ;;
[Aa]5)
   STP_PAPERSIZE=A5
   GS_PAPERSIZE="-sPAPERSIZE=a5"
   ;;
[Ss][Tt][Aa][Tt][Mm][Ee][Nn][Tt]|[Hh][Aa][Ll][Ff][Ll][Ee][Tt][Tt][Ee][Rr])
   STP_PAPERSIZE=Statement
   GS_PAPERSIZE="-sPAPERSIZE=halfletter"
   ;;
[Ee][Xx][Ee][Cc][Uu][Tt][Ii][Vv][Ee])
   STP_PAPERSIZE=Executive
# postscript doesn't know about executive, maybe because that word is
# how you ask for an interactive interpreter...
   GS_PAPERSIZE="-dDEVICEWIDTHPOINTS=522 -dDEVICEHEIGHTPOINTS=756"
   ;;
# ignoring these, will never need them, and can't think of a friendly name...
# w283h420 Hagaki Card 100 x 148 mm (Japanese postcard)
# w420h567 Oufuku Card 148 x 200 mm (Japanese return postcard)
#
[Aa]6)
   STP_PAPERSIZE=A6
   GS_PAPERSIZE="-sPAPERSIZE=a6"
   ;;
[Ww]360[Hh]576|5x8)
   STP_PAPERSIZE=w360h576
   GS_PAPERSIZE="-dDEVICEWIDTHPOINTS=360 -dDEVICEHEIGHTPOINTS=576"
   ;;
8x10)
   STP_PAPERSIZE=8x10
   GS_PAPERSIZE="-dDEVICEWIDTHPOINTS=576 -dDEVICEHEIGHTPOINTS=720"
   ;;
# ignoring this, not clear from printer manual if supported or if
# jisb5 is favored instead
# ISOB5 B5 ISO 176mm x 250mm
#
[Cc][Oo][Mm]10|[Nn][Rr]10|[Ee][Nn][Vv]10)
   STP_PAPERSIZE=COM10
   GS_PAPERSIZE="-dDEVICEWIDTHPOINTS=297 -dDEVICEHEIGHTPOINTS=684"
   ;;
[Cc]6)
   STP_PAPERSIZE=C6
   GS_PAPERSIZE="-dDEVICEWIDTHPOINTS=323 -dDEVICEHEIGHTPOINTS=459"
   ;;
[Dd][Ll])
   STP_PAPERSIZE=DL
   GS_PAPERSIZE="-dDEVICEWIDTHPOINTS=311 -dDEVICEHEIGHTPOINTS=623"
   ;;
[Pp][Oo][Ss][Tt][Cc][Aa][Rr][Dd])
   STP_PAPERSIZE=Postcard
   GS_PAPERSIZE="-dDEVICEWIDTHPOINTS=283 -dDEVICEHEIGHTPOINTS=416"
   ;;
*)
   lperror "unrecognized paper size ${ORIGINAL_STP_PAPERSIZE}"
   ;;
esac

# standardize MEDIATYPE
ORIGINAL_MEDIATYPE="${MEDIATYPE}"
case "${MEDIATYPE}" in
[Pp][Ll][Aa][Ii][Nn]) MEDIATYPE=Plain;;
[Pp][Ll][Aa][Ii][Nn][Ff][Aa][Ss][Tt]) MEDIATYPE=PlainFast;;
[Pp][Oo][Ss][Tt][Cc][Aa][Rr][Dd]) MEDIATYPE=Postcard;;
[Gg][Ll][Oo][Ss][Ss][Yy][Ff][Ii][Ll][Mm]) MEDIATYPE=GlossyFilm;;
[Tt][Rr][Aa][Nn][Ss][Pp][Aa][Rr][Ee][Nn][Cc][Yy]) MEDIATYPE=Transparency;;
[Ee][Nn][Vv][Ee][Ll][Oo][Pp][Ee]) MEDIATYPE=Envelope;;
[Bb][Aa][Cc][Kk][Ff][Ii][Ll][Mm]) MEDIATYPE=BackFilm;;
[Mm][Aa][Tt][Tt][Ee]) MEDIATYPE=Matte;;
[Ii][Nn][Kk][Jj][Ee][Tt]) MEDIATYPE=Inkjet;;
[Cc][Oo][Aa][Tt][Ee][Dd]) MEDIATYPE=Coated;;
[Pp][Hh][Oo][Tt][Oo]) MEDIATYPE=Photo;;
[Gg][Ll][Oo][Ss][Ss][Yy][Pp][Hh][Oo][Tt][Oo]) MEDIATYPE=GlossyPhoto;;
[Ll][Uu][Ss][Tt][Ee][Rr]) MEDIATYPE=Luster;;
[Gg][Ll][Oo][Ss][Ss][Yy][Pp][Aa][Pp][Ee][Rr]) MEDIATYPE=GlossyPaper;;
[Ii][Ll][Ff][Oo][Rr][Dd]) MEDIATYPE=Ilford;;
[Oo][Tt][Hh][Ee][Rr]) MEDIATYPE=Other;;
*) lperror "Invalid media type ${ORIGINAL_MEDIATYPE}";;
esac

# other driver options not presently exposed:
# -dCyan=xxx xxx: 0.0 ... 4.0 (1.0)
# -dMagenta=xxx xxx: 0.0 ... 4.0 (1.0)
# -dYellow=xxx xxx: 0.0 ... 4.0 (1.0)
# -dBrightness=xxx xxx: 0.0 ... 2.0 (1.0)
# -dContrast=xxx xxx: 0.0 ... 4.0 (1.0)
# -dGamma=xxx xxx: 0.1 ... 4.0 (1.0)
# -dDensity=xxx xxx: 0.1 ... 2.0 (1.0)
# -dSaturation=xxx xxx: 0.0 ... 9.0 (1.0)

${GSCMD} -sModel="${MODEL}" -r"${RESOLUTION}" -sQuality=${QUALITY} \
   -sInkType="${INKTYPE}" -sMediaType="${MEDIATYPE}" \
   ${GS_PAPERSIZE} -sPaperSize="${STP_PAPERSIZE}" \
    -sDither="${DITHER}" -dImageType="${IMAGETYPE}" -dColor="${COLOR}" \
    - || \
lperror "ghostscript failed"
================================ cut here ================================

-- 
mailto:rlhamil@smart.net  http://www.smart.net/~rlhamil


Relevant Pages

  • Re: Printer for linux?
    ... postscript formatted data for printing and since Joe Public can't afford ... This is what I thought function of ghostscript is, ... If you install CUPS it should install most everything you need ...
    (Debian-User)
  • Re: CUPS: Help configuring dot matrix printer
    ... gs-pdfencrypt, cupsys-pstoraster ... Ghostscript is used for PostScript preview and printing. ... intended mostly for use with the Common UNIX Printing System from Easy Software ...
    (comp.os.linux.misc)
  • Re: [Full-disclosure] Multiple memory corruption vulnerabilities in Ghostscript
    ... PostScript files", I was referring to the act of opening PostScript ... Ghostscript developers to release a fix for these issues. ... The disclosure of these bugs without a fix is unfortunate, ... Last I checked, PDF wasn't a Turing-complete ...
    (Full-Disclosure)
  • Re: triouble with my Deskjet 500
    ... to print xv images or anything else PostScript. ... use Ghostscript to scan-convert and print it. ... we redirect stdout to stderr ...
    (freebsd-questions)