From: emanuel@dxcern.cern.ch (Emanuel Machado)
Subject: Re: Printing a PS File from VB
Organization: CERN European Lab for Particle Physics
Date: Sun, 4 Oct 1992 22:56:43 GMT

In   <1992Oct2.195924.18573@e2big.mko.dec.com>   hilman@camry.enet.dec.com
(Eric Hilman) writes:

>A hack that appears to work is to SHELL to a script that does COPY foo.ps lpt1:
>in foo.ps I can include the ps commands to switch between portrait and 
>landscape.  The trick is to SHELL to a .pif file with the minimized, with
>focus options set.  Also set the foreground priority at 10000 so that it runs.

	This works in principle, but.

        The problem I found, was that copying directly to the  port  seems
not  to  take  into account possible "flow control", and for large files I
found that it gave some errors.

        Also, and this may depend on the  printer  (I'm  using  an  oldish
Apple  LaserWriter  Plus, out of COM2: -- no parallel port), if you feed a
job to the printer while it is working on another job, that job is  either
reset,  or  the  printer  simply  hangs.  Noticing how the printer manager
"managed" to get the job done pretty well, I wanted to give IT  the  print
jobs to manage.

>Open "PRN:" etc or OPEN "LPT:" etc do not work. I was hoping that there was
>another way or a dll/vbx around that allowed one to set things up from the 
>software.

        You probably can do that with OPEN  "LPT1"  (without  the  comas).
There's  a  useful  tips  file  in  SIMTEL20  (I think, or was it garbo?),
compiled by Nelson Ford.  Check for the file vb-tips.zip.

>eric hilman

        The  idea  mentioned  about  using  a  generic  printer  is   very
interesting.  I  faced two problems, though.  How do I (using VB) select a
non-default printer (I don't want to loose my  LaserWriter  as  a  default
one)?  And,  what  kind  of  dialog  goes  on  between  the driver and the
printer?  Does, for instance, the driver  have  to  know  that  a  certain
printer  IS  a  PS  printer?  Or  does it spew the data expecting it to be
correctly interpreted? (Like, is the driver actually  asking  the  printer
some inteligent questions?)

        If the driver requires some knowledge of  the  printer,  then  the
generic  printer  driver  may not be enough.  It worked well for the cases
I've tried (using it as a default one),  but  I  wonder  if  this  is  the
correct procedure.

        I actually managed to solve the issue using escapes.  Not  without
the  help  of  some of you out there.  Thanks a lot, I really appreciated.
(Sorry, don't have your names at hand now, to cite you.  But you know  who
you are)

	Here are the outlines:

	. For the text, after I checked that it was a PS file, I read it as
a binary file. It helps tremendously if you want to deal with large files.
What you probably end up doing is to read a buffer, send it to the printer
(@#$@#$ limitation in buffer size!!), and repeat until done. See tips file
for details on buffers.

	This is using VB 1.0, with SDK 3.0

	. create a structure:

	Type PassThroughType
		wCount As Integer
		sBuffer As String * 32000       ' didn't really try bigger
	End Type                                ' come to think of it

	Type PointerToString                    ' We will use an object of
		Text As String * 32             ' this type as a pointer
	End Type

	. Start your document:

	Dim fname As PointerToString
	Dim TextData As PassThroughType

	fname.text = FileName$

	(get your buffer$ now)

	TextData.wCount = Len(buffer$)
	TextData.text = buffer$

	' now for the actual escapes...

	r% = Escape (Printer.hDC, STARTDOC, Len (FileName$), fname, NULL)

	' so you get a long pointer to a string. This gives the header to
	' be sent to the PM

	r% = Escape (Printer.hDC, PASSTHROUGH, TextData.wCount + Len(I%),
	     TextData, NULL)    ' in one line, of course

	' repeat for all buffers, and

	r% = Escape (Printer.hDC, ENDDOCAPI, 0, NULL, NULL)

	' Note: DON'T end up with Printer.EndDoc. Somehow it doesn't work.
	' By the way, I noted that in 3.1 there are also functions for
	' StartDoc and EndDoc, which will give you three different ways of
	' doing the same thing: by Printer.EndDoc, Escape (... ENDDOC... )
	' and EndDocApi(...). Hope this will mean a clean-up of the code.

	It actually runs fine, BUT.

        When I first printed this, I got a very nice picture,  BUT  scaled
down  and  mirrored.  While  looking  at  the  actual  PS code produced, I
noticed some scaling was  done  immediately  AFTER  the  STARTDOC  escape.
Anyone  knows how can one get rid of this problem elegantly?  The method I
now use, is to  issue  a  PostScript  "grestore"  immediately  after  that
escape.  I  do this using again the PASSTHROUGH escape.  I'm not very well
versed in PostScript myself, so I don't know yet whether this is enough to
get the default values.

	I would love to use the POSTSCRIPT_IGNORE escape, but it didn't
seem to work in the 3.0 SDK. Is it true? Or was it my mistake?

	Hope this helps. Thanks again for your help.

	Emanuel
-- 
Emanuel T.M. Machado (PPE/CPL)|  "Who Wills, Can     | European Laboratory for
  __                        _ |   Who Tries, Does    | Particle Physics (CERN)
 /_  ____   _   __  , , _  |/ |   Who Loves, Lives"  | -- Internet Address --
/_  / / / /_ < / / /_/ <'_ /_ |    -- Anne McCaffery | emanuel@dxcern.cern.ch