PS code to write a Special File?
Quote:
> Hello all you postscript folks,
> I need a very simple filter or postscript code snippet that does the
> following:
> I have a textfile which is an image bitmap which has 640 pixels per line
> and 480 lines (like a VGA output). This file is quite simple it either
> has a "1" or a "0" character at each location. I have discovered that
> by using a Couier fixed typeface at 2 point font on landscape paper with
> margins set at 1/8" and 1 point spacing between lines I get the entire
> image on one sheet of paper.
> Now what I need is the postscript code to make those setting work. I
Do you literally need to have little bitty '0's and '1's squished
together 1 point apart, or would you be satisfied to render your file as
an image (with light and dark regions instead of tiny numbers)?
If you really need the tiny numbers, the code below will probably do the
trick, but boy those numbers are ugly.
The pretty way would be to use the image operator; one of its arguments
is a procedure that provides the next line of image data each time it
is called, which makes it very easy to do things like this. Just write
a procedure that reads the next line from your text file, mungs the '1'
and
'0' characters into binary ones and zeros, and returns them.
You can now use all the scale, translate, rotate, etc. operators to put
your image anywhere on the page you would like. The code would not be
much more complicated than this (proof left as an exercise for the
reader).
You should have a copy of the PostScript Language Reference Manual, 2nd
Edition,
from Adobe, but if you don't, in a pinch you can use
http://www.lumcorp.com/Web/PSWeb/index.html .
For the code below, if you save it in a file snarf.ps, and your input
data are
in myfile.in, you would run gs as in:
$ gs -sFILENAME=myfile.in snarf.ps
Use the other command line options to specify the right printer device,
etc.
-Chap
--------snip-------
/buf 641 string def
/inp FILENAME (r) file def
/inch { 72 mul } def
/eighth { 8 div } def
8.5 inch 0 translate % move origin to (8.5, 0)
90 rotate % landscape
1 eighth inch 8.5 -1 eighth add inch moveto % to (1/8, 8.5 - 1/8)
/Courier findfont 2 scalefont setfont % 2-pt Courier
/line { save exch show restore 0 -1 rmoveto } def % print a line then
down 1 pt
{ inp buf readline not { exit } if line } loop % do 'em all
pop
showpage
quit