Postscript Level 3 text to PS conversion tool

Postscript Level 3 text to PS conversion tool

am 20.11.2007 07:03:20 von Yaw Lim

I used to use Enscript to print text files. But we now have a new
printer that supports only PS level 3 and the otputs from Enscript
don't seem to print well. Can anybody suggest an alternative to
Enscript (not a2ps)?

/Why Tea

Re: Postscript Level 3 text to PS conversion tool

am 20.11.2007 17:47:42 von Edward Rosten

On Nov 19, 11:03 pm, Why Tea wrote:
> I used to use Enscript to print text files. But we now have a new
> printer that supports only PS level 3

What kind of postscript does enscript output? PS level 3 is a superset
of PS level 2, ie all Level 2 (and therefore all Level 1) programs
should execute just fine.

> and the otputs from Enscript
> don't seem to print well. Can anybody suggest an alternative to
> Enscript (not a2ps)?

Why not a2ps?


Anyway, I have an old buggy and maybe working program for this job.
You can have it.
Note the header= line. You have to set this correctly. Id doesn't
conform to DSC: it determines the size of the page and fits the text
automatically. Some features are missing. YMMV, etc.


------------------------File
text2ps------------------------------------


#!/bin/bash

p=${0##*/}

header=~/code/postscript/text2ps.ps


help="usage: $p -lhbctwsi [files ...]
$p takes ASCII text and produces pages. The pages will always be the
same
number of columns wide, independent of the output device. The number
of rows
will be adjusted to make the text fit.

-c # Make the page # columns wide. Defaults to 80.
-t # Expand tabs to # spaces. Default it 8.
-w Wrap lines to fit in the page.
-i # Indent wrapped lines by # columns. Default is 10.
-s Show wrapped lines by printing a marker in the indent.
-b Make every real second page blank.
-l Landscape.
-L # left margin size
-R # right margin size
-T # top margin size
-B # bottom margin size
-h This.
"

export OPTERR=0
extra=
argerr=0
expand=8

function badarg()
{
[ $argerr = 0 ] && echo "$p: bad arguments." 1>&2 && argerr=1
}

function ext()
{
extra="${extra} $*"
}



function isnum()
{
if echo "$*" | grep -qv '[0-9]'
then
badarg
echo "-$arg requires a number, not gibberish." 1>&2
return 1
fi

return 0
}


a1=${1#-}

while getopts ":c:t:wi:hsblL:R:T:B:" arg
do
a1="${a1#$arg}"

if [ "$OPTARG" != "" ]
then

#if we have -o ARG
if [ "$a1" = "" ]
then
shift
a1=
else
a1=
fi
fi

if [ x"$a1" = x ]
then
shift
a1="${1#-}"
export OPTIND=1
:
fi

case "$arg"
in
c)
if isnum "$OPTARG"
then
extra="${extra} /cols $OPTARG def"
fi
;;

t)
if isnum "$OPTARG"
then
expand="$OPTARG"
fi
;;

w)
extra="${extra} /wrap true def"
;;

b)
extra="${extra} /blank true def"
;;

s)
extra="${extra} /showwrap true def"
;;

l)
ext "/landscape true def"
;;

h)
echo
echo "$help"
echo
exit 0
;;

i)
if isnum "$OPTARG"
then
extra="${extra} /wrapindent $OPTARG def"
fi
;;

L)
if isnum "$OPTARG"
then
extra="${extra} /leftmargin $OPTARG def"
fi
;;

R)
if isnum "$OPTARG"
then
extra="${extra} /rightmargin $OPTARG def"
fi
;;

T)
if isnum "$OPTARG"
then
extra="${extra} /topmargin $OPTARG def"
fi
;;

B)
if isnum "$OPTARG"
then
extra="${extra} /bottommargin $OPTARG def"
fi
;;

\?|:)
badarg

case "$OPTARG"
in
c|t|i)
echo "-$OPTARG requires an argument." 1>&2
;;
*)
echo "-$OPTARG is not a recognised option." 1>&2
esac
;;

*)
:
;;

esac
done

if [ $argerr != 0 ]
then
echo
#echo "$help"
exit 1
fi

export extra

expand -t$expand $@ | sed -e's/[(\)]/\\&/g' -e's/^/(/' -e's/$/)l/' |
cat "$header" <(echo $extra) - <(echo newpage)


-----------------------file
test2ps.ps------------------------------------------


%!PS

%Default arguments
/cols 80 def
/wrap false def
/wrapindent 10 def
/showrap false def
/blank false def
/landscape false def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
%%%%%%%%%
%Initialisation

/font { /Courier findfont } def
/font_size 0 def
/char_witdh 0 def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%
%%%%%%%%%
% Functions

/topmargin 10 def
/bottommargin 10 def
/rightmargin 10 def
/leftmargin 10 def

/find_page_size
{
clippath pathbbox
/ymax exch topmargin sub def
/xmax exch rightmargin sub def
/ymin exch bottommargin add def
/xmin exch leftmargin add def
/width xmax xmin sub def
} def

/choose_font
{
font 10 scalefont setfont

%Find the width of a sincle character for font size 10, length 50
(**************************************************)
stringwidth
pop
50 div
%Page width: width = fontsize * cols * <- / 10
%fontsize = width * 10 / (cols * <-)

dup /char_width exch def

width 10 mul exch cols mul div

/font_size exch def

font font_size scalefont setfont
} def


/newpage
{
%If font size is zero, this is the first time.
0 font_size eq
{
landscape
{
90 rotate
} if

find_page_size
choose_font
}{
showpage
blank
{
showpage
} if

landscape
{
90 rotate
} if

} ifelse

xmin ymax font_size sub moveto
currentpoint /ypos exch def pop

} def


/l
{
0 font_size eq
{
newpage
} if

%check the length
wrap
{
dup length cols gt
{





}if
}{
show
} ifelse

xmin /ypos ypos font_size sub def ypos moveto

ypos ymin lt
{
newpage
} if
} def


------------------------End------------------------------

-Ed

Re: Postscript Level 3 text to PS conversion tool

am 20.11.2007 20:16:04 von Martin Klar

Why Tea schrieb:
> I used to use Enscript to print text files. But we now have a new
> printer that supports only PS level 3 and the otputs from Enscript
> don't seem to print well. Can anybody suggest an alternative to
> Enscript (not a2ps)?


ps2ps -dLanguageLevel=3 in.ps out.ps


HTH Martin