Article View: comp.lang.postscript
Article #5529Line Printer Simulator
From: bruce.r.fowler
Date: Wed, 01 May 1991 15:49
Date: Wed, 01 May 1991 15:49
103 lines
5160 bytes
5160 bytes
Hi,
Seems like a lot of folks want to be able to use their PostScript
printers as "dumb" lineprinters, at least for that occasional source listing
or whatever. I've been waiting for a brute-simple, non-elegant solution to
be posted, but since I haven't seen it, here's one. I wrote a version of
this a year or so ago that did only straight typewriter-style "portrait"
output. Several spin-offs occurred in the interim, to handle landscape and
other formats. What I have done for this posting (correctly, I hope!)
is combine three of the more useful formats in one. DON'T RUN THIS CODE
THE WAY IT COMES OUT OF THE BOX. Read the first few comment lines and grep
it as indicated to extract three PostScript programs. You could also remove
some of the comments from the final product if you would like, to save a few
milliseconds of printer time. Careful, though, one of those (%)'s is
significant!
Just concatenate the version that gives the output format you want
on the front of what you want to print. A shell script is useful for doing
the concatenation, or you could do it in an lp spooler. The code handles
tabs, and it can detect (^L) on a line by itself as a "form-feed" indicator.
The approach was to keep it simple and specialized, and just generate more
versions to do other specialized things. Even if you are not a PostScript
freak, a bit of study should allow you to hack this to do your favorite
thing, for example different spacing of tabs. I hereby put this in the
Public Domain, so do whatever you like with it.
Enjoy,
Bruce Fowler
AT&T HR 2F-027 (908)615-5559 Dept 51342 brf@mink.att.com
+---------------------------------------------------------+
| *** The Twilight Zone - Love it or Leave it. *** |
+---------------------------------------------------------+
____ ==> [ unzip here ]
|____)-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-8-
% This is three PostScript procs in one. Run one of the following :L:S:P:
% to get the flavor you want: :L:S:P:
% $ grep -v :L: lp_sim.ps >landscape.ps :L:S:P:
% $ grep -v :S: lp_sim.ps >sourcelst.ps :L:S:P:
% $ grep -v :P: lp_sim.ps >portrait.ps :L:S:P:
% :L:S:P:
% Postscript line printer simulator. Cat this onto front of file to be
% printed. Replaces tabs with blanks (x8). Line with only ^L causes
% form feed. Leaves margins, for punching holes. For 8-1/2 x 11 paper.
% Prints 66 lines in landscape mode, 9 point type with 8 point spacing. :P:S:
% Prints 90 lines by 100 columns of 9 point type with 8 point spacing. :L:P:
% Prints 66 lines by 80 columns of 12 point type with 11 point spacing. :L:S:
%
/toppg 556 def % Top of page :P:S:
/toppg 756 def % Top of page :L:P:
/toppg 759 def % Top of page :L:S:
/botpg 33 def % Last line goes here :P:S:
/botpg 36 def % Last line goes here :L:P:
/botpg 33 def % Last line goes here :L:S:
/lmargin 36 def % Left margin (0.5") :P:S:
/lmargin 36 def % Left margin (0.5") :L:P:
/lmargin 54 def % Left margin (0.75") :L:S:
/vinc -8 def % Step to next line :P:S:
/vinc -8 def % Step to next line :L:P:
/vinc -11 def % Step to next line :L:S:
/curline 512 string def % Storage for current line
/dotab { %def % Move right to next tab stop
dup show length
dup 8 mod 8 exch sub
dup ( ) stringwidth pop mul 0 rmoveto
add exch pop 3 -1 roll add exch
} bind def
/doit { %def % File printing proc
/vp toppg def % Start at top of page
{ % Read to end of file
infil curline readline {
dup (\014) eq { % New page if ^L
pop % Dump the line
vp toppg ne { % Go to top of page
showpage %:L:
gsave showpage grestore %:P:S:
/vp toppg def
} if
}{
lmargin vp moveto % Position for output
0 exch
{ % loop % Output string from readline
(\t) search {dotab} {show exit} ifelse
} loop
pop
/vp vp vinc add def % Move to next line
vp botpg le { % New page if off the end
showpage %:L:
gsave showpage grestore %:P:S:
/vp toppg def
} if
} ifelse
}{exit} ifelse
} loop
vp toppg ne {showpage} if
} bind def
% Initialize and start the action
/infil (%stdin) (r) file def % Source of input to print
/Courier findfont 9 scalefont setfont % Scaled Courier :P:S:
/Courier-Bold findfont 9 scalefont setfont % Scaled Courier :L:P:
/Courier-Bold findfont [11.25 0 0 12 0 0] makefont setfont % Courier :L:S:
[ 0 1 -1 0 612 0 ] concat % Fit to landscape orientation :P:S:
% Invoke printing proc. Data follows
doit
Technical Details
Message-ID:
<1991May1.154951.17280@cbnewsi.att.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!cbnewsi!brfShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!cbnewsi!brf From: brf@cbnewsi.att.com (bruce.r.fowler) Newsgroups: comp.lang.postscript Subject: Line Printer Simulator Keywords: ascii2ps lp dumb_print Message-ID: <1991May1.154951.17280@cbnewsi.att.com> Date: 1 May 91 15:49:51 GMT Organization: AT&T Bell Laboratories Lines: 103