printing from within Cygwin

Igor Pechtchanski pechtcha@cs.nyu.edu
Mon Sep 16 13:35:00 GMT 2002


On Mon, 16 Sep 2002, Jason Tishler wrote:

> Igor,
>
> On Fri, Aug 30, 2002 at 05:59:39PM -0400, Igor Pechtchanski wrote:
> > Note the disabled support for gsprint -- I couldn't get it to work
> > properly.  If anyone can get the gsprint part to work, please let me
> > know.
>
> I use the attached shell script as "lpr" on my home computer with a
> direct or network (i.e., lpd) attached PCL printer.  Note that I'm using
> the Win32 GSView (and GhostScript).
>
> Jason

Jason,
I know GSPrint can work with Windows printers.  It works fine if you only
want to use the windows default printer.  I couldn't, however, get it to
work correctly with the -printer and -query options (well, the -printer
part is mostly shell quoting issues, but the -query just doesn't seem to
work, somehow).  Any insight will be appreciated.  I'm attaching the
script that I currently have.

A question about your script: you're using the '-_' option, which doesn't
seem to be documented on the GSPrint page (
http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm ).  What exactly does it
do?

I also found this thread extremely interesting and relevant:
http://sources.redhat.com/ml/cygwin/2000-11/msg01570.html
a2ps seems like the perfect solution for lp/lpr.  Is it ever going to
become a cygwin package (
http://www.cygwin.com/ml/cygwin/2001-08/msg01240.html )?

Thanks,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Water molecules expand as they grow warmer" (C) Popular Science, Oct'02, p.51
-------------- next part --------------
#! /bin/sh

# Author: Pierre A. Humblet pierre.humblet@ieee.org  

#   Created: May 2000

#   Modified: March 2001 Add support for gsprint

# Modify and redistribute freely. Use at your own risk.

# This is distributed as part of the Xfig-Cygwin package.

#

# Modified: Igor Pechtchanski pechtcha@cs.nyu.edu

#   Modified: February 2002 Add support for -P and $PRINTER

#   Modified: February 2002 Add support for stdin

#   Modified: March 2002 Disable gsprint support

#   Modified: May 2002 Tweak gs options

#   Modified: August 2002 Add -Q and -h; make presentable

#   Modified: September 2002 Enable gsprint support

#

# Script to print postscript from stdin or the file given as 

#   single argument.

# Relies on the existence of gsprint 

#   ( http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm )

#   or of gs (ghostscript) with device mswinpr2

#



#GSLP=gslp.ps

GSLP=`cygpath -w /usr/local/bin/gslp.ps`

USAGE="\

Usage: $0 [--help] [--query|-Q]

       [--printer <printer>|-P <printer>|-P<printer>] [file_1 .. file_n]"



while [ $# -gt 0 ]; do

 case "$1" in

  -h | --help)    shift; echo "$USAGE"; exit 0 ;;

  -Q | --query)   shift; QUERY=true ;;

  -P | --printer) shift; PRINTER="$1"; shift

                  if [ -z "$PRINTER" ]; then

                   echo Please specify a printer with -P 1>&2

                   exit 2

                  fi ;;

  -P*)            PRINTER="${1#-P}"; shift ;;

  --)             shift; break ;;

  -*)             echo "$0: $1: invalid option" 1>&2

  		  echo "$USAGE" 1>&2

  		  exit 2 ;;

  *)              break ;;

 esac

done



if [ "${1:-}" = "" ]

then

# file=-_

 file='%stdin'

else

 file="$1"

 if [ ! -r "$file" ]

 then

  file="${file}.ps"

  if [ ! -r "$file" ]

  then

   echo Cannot read "$file" 1>&2

   exit

  fi

 fi

 file=`cygpath -w "$file"`

fi



#echo "Printing '${file}' to $PRINTER"



# Look for Ghostgum Gsview in the registry

GSPRINT=""

VERSIONS=`regtool -q list '\HKLM\SOFTWARE\Ghostgum\Gsview'`

# Scan all versions, keep the last good one

for VER in ${VERSIONS}

do

 WHERE_W=`regtool -q get '\HKLM\SOFTWARE\Ghostgum\Gsview\'"${VER}"`

 if [ -n "$WHERE_W" ]

 then

  WHERE_U=`cygpath -u "$WHERE_W"`

  GSPRINT_CAND="${WHERE_U}/gsview/gsprint.exe"

  if [ -x "$GSPRINT_CAND" ]

  then

   GSPRINT="${GSPRINT_CAND}"

  fi

 fi

done   



# Escape backslashes in $PRINTER

PRINTER=`echo $PRINTER | sed 's/\\\\/\\\\\\\\/g'`



if [ -n "$GSPRINT" ]

then

# Use gsprint

 PRINTSTR=""

 if [ -n "$PRINTER" ]

 then

  PRINTSTR="-printer $PRINTER -noquery"

 elif [ -n "$QUERY" ]

 then

  PRINTSTR='-query'

 else

  PRINTSTR='-noquery -noprinter'

 fi

 echo "${GSPRINT}" -q $PRINTSTR -c mark /NoCancel true /UserSettings '<<' /MaxResolution 1200 '>>' -f -sPROGNAME=lpr "${file}"

 "${GSPRINT}" -q $PRINTSTR -c mark /NoCancel true /UserSettings '<<' /MaxResolution 1200 '>>' -f -sPROGNAME=lpr "${file}"

else

# Try gs

 if [ -n "$PRINTER" ]

 then

  PRINTSTR='/OutputFile (\\\\spool\\'"$PRINTER"')'

 elif [ -n "$QUERY" ]

 then

  PRINTSTR='/QueryUser 1'

 else

  PRINTSTR='/QueryUser 3'

 fi

# echo "Printing '${file}' to $PRINTER using gs -dNOPAUSE -dBATCH -q -c mark /NoCancel true $PRINTSTR /UserSettings '<<' /MaxResolution 1200 '>>' '(mswinpr2)' finddevice putdeviceprops setdevice -f -sPROGNAME=lpr -- $GSLP --detect -B ${file}"

 gs -dNOPAUSE -dBATCH -q -c mark /NoCancel true "$PRINTSTR" /UserSettings '<<' /MaxResolution 1200 '>>' '(mswinpr2)' finddevice putdeviceprops setdevice -f -sPROGNAME=lpr -- $GSLP --detect -B "${file}"

fi



# This worked: "gs -dNOPAUSE -dBATCH -q -sDEVICE=mswinpr2 -r600 '-sOutputFile=\\spool\$PRINTER' -dNoCancel -sPROGNAME=gslp -- gslp.ps ${file}"

# So did this: "gs -dNOPAUSE -dBATCH -q -c mark /NoCancel true /QueryUser 3 /OutputFile '(\\spool\lp.scs.cs.nyu.edu)' /UserSettings '<<' /MaxResolution 1200 '>>' '(mswinpr2)' finddevice putdeviceprops setdevice -f -sPROGNAME=gslp -- gslp.ps ${file}"

-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list