===============================================================================
MS-DOS Printing package
===============================================================================
Compiled by DI (FH) Ludwig Ertl, 2010
Contains a special compiled version of Artifex GhostPCL: 
					http://www.artifex.com/downloads/
Contains URW Fonts by Artifex.
Contains PRN2FILE by Gurtjak D., Ignatenko I., Goldberg A. 
Contains some handwritten helper applications by Ludwig Ertl

What is it all about?
=====================
Users of MS-DOS application, i.e. users of the SPI OpenAccess Database program
often have a problem with printing from Windows.
Altough, there are many pritners out on the market, that support PCL properly,
there are also cheap GDI-only printers that cannot be controlled by standard 
Escape-sequences anymore. They work perfectly well with their Windows-drivers 
but you cannot control the printers directly via PCL oder Epson ESC/P 
Escape-sequences anymore.
Another issue is PDF-Creation from DOS-applications: If you have a printer 
that is capable of PCL-commands, you are still facing the issue that you 
cannot create a PDF file from your Escape-sequences easily.
This package tries to fill the gap.
There are quite a lot of applications commercially available (i.e. dosprn), 
which try to solve this problem too, but this package is under GPL license, 
so you can use and distribute it freely.

What options do I have?
=======================
First of all, there are 2 Strategies for printing from DOS-Applications:
If you only need a possibility to print plain characters from DOS or you 
are using simple Epson  LQ/SQ ESC/P Sequences, and you just need to be able
to print to your Windows-printer, my little dospr-Application may be 
sufficient for your needs. It maps the most common Epson ESC/P Sequences 
to GDI drawings for windows printers.
If this solution is enough for you, you just have to keep the following 
files:

watcher.exe
epson.seq
dospr.exe
_escp2prn.bat 
escp2prn.bat 
PRN2FILE.COM 
stop.bat

and can delete the rest (which is all PCL-stuff) to save precious space.
I will later describe how it works.
Be aware that there is no PDF-conversion option for this solution, so you 
need to install a PDF-printer like http://freepdfxp.de/ to convert 
ESC/P to PDF.

On the other hand, if you want to take the full potential of the mighty 
PCL-language, you need the support of GhostPCL which is also included in this
package.
Before compiling, I modified the Makefile of the standard GhostPCL a bit, 
so that you also should be able to print to a Windows-printer directly (I 
added the mswinpr2 device to the list of available output devices).
For Ghostpcl, the following files and directories are needed:

watcher.exe
PRN2FILE.COM 
stop.bat
pclenv.bat
_pcl2pdf.bat
_pcl2prn.bat
pcl2pdf.bat
pcl2prn.bat
pcl6.exe
urwfonts

As you can see, Ghostpcl is able to create PDF files directly.



How does this all work?
=======================

1) Capture the printer output
-----------------------------
First of all, you need a possibility to capture the output of your DOS 
application in order to send it to your desired output device.

Some applications, like SPI OpenAccess, have the possibility to set the output
device to a file, so in this case, the job is easy:
Setup your application to print to a certain file. I recommend using 
C:\PRNSPL, as the batch-files in this package are defaulting to this file for 
compatibility with PRN2FILE.

If the application insists on printing to the PRN or LPT-Device, there is a 
little program that can redirect the printer output to a file: PRN2FILE.COM
You just need to start this application prior to your DOS App and it will 
redirect the output to C:\PRNSPL (or the file you specify on commandline).
If you want to launch PRN2FILE automatically, add it to your 
%SYSTEMROOT%\SYSTEM32\AUTOEXEC.NT file.


2) Automatically pipe the printer output to the conversion tool
---------------------------------------------------------------
Now if you are printing from your DOS application, you want to automatically 
initiate the conversion tool to output it to your printer or convert to PDF, 
without starting the process manually.
Therefore I developed a little application the monitors some file (in our 
case the spool file) and starts an application, as soon as a file change is 
detected (i.e. data is written to the file).
The syntax is:

  watcher <File/Dir to watch> <Command to execute>

The watcher-program passes the file that changed as commandline argument to 
the <Command to execute> so that the application can process it.

There are 3 sample files that demonstrate the use of watcher:

pcl2pdf.bat
pcl2prn.bat
escp2prn.bat

If you have a look at escp2prn.bat for example, it contains:

  start watcher C:\PRNSPL %CD%\_escp2prn.bat

So watcher monitors the File C:\PRNSPL and executes the file _escp2prn.bat in 
the current directory. Be aware, that watcher needs a FULL PATH for its 
operations, therefore the %CD% Shell variable is expanded to the current 
directory.

As you may have noticed, the files with the underscores in front are the 
"worker" files for the starters.

You should delete the spool file after processing to prevent the application 
from appending data to it. As you can see in the worker files with the 
underscores, this is done in there.

If you want to stop the watcher, you have to kill its process. You can use 
stop.bat for this purpose, which contains:

  taskkill /F /IM watcher.exe

This is not suitable if you want to watch the output of more files, but 
it's just important to know that killing watcher.exe is ok to stop it.


3) Processing the spool files
-----------------------------

a) Processing ESC/P files or plain text files
If you are working with ESC/P sequences or just want to print out simple 
text files to a GDI printer, my little dospr Application will be enough for 
your needs. It is capable of a few formatting commands. The mapping of 
ESC-Sequences to actions is done with a sequence file. In our case, it is 
epson.seq which defines the sequences as decimal ascii-codes seperated by 
commas. If more than one command does the appropriate action, the
commands are seperated by a pipe character. If you want to ignore certain 
escape-sequences, add them to the Ignore_Chars-Entry.
Sequence names should be pretty self-explaining.
Sourcecode is included, so you can adapt the application to your needs, if 
you are a programmer.

dospr has the following syntax:

  dospr <-f sequence file> [-p Printer name] [-s] <Spoolfile>

  -f Specified a file with the escape-sequences to use. You can make your own 
     file or adapt epson.seq to your needs. If an action isn't supported, 
     just delete it from the file.
  -p You can specify a name of the printer to print to. If you don't specify
     a printer, the system default printer will be used.
  -s If you set this parameter, you get a selection dialog to choose the 
     printer.

Files should be specified including full pathnames.

b) Processing PCL files
Processing PCL commands is a more complex task, as the language itself is 
very powerful. Therefore we need a 3rd Party application to do the processing.
Artifex GhostPCL is perfect for our needs. However the default Makefile for 
Windows has the drawback, that it doesn't implement an output device to 
directly print to a Windows printer by default, even tough it is supported 
by Ghostscript via the mswinpr2 output device.
Therefore I modified the makefile a bit and compiled in support for this 
device.

pcl6 is very powerful and has a wide range of options that are too many to 
explain here, therefore I'm just focusing on the basic implementation for the
most common tasks. In order to get GhostPCL running, you need to have the 
urwfonts available and set the PCLFONTSOURCE to the right directory 
(including full path). The path has to be terminated
by a / and \ need to be replaced by /. This is done for you in the 
pclenv.bat file so that you don't have to worry about it.
You are also able to add additional PJL -commands for setting up your output 
precisely, so it may still be a good idea to have a look at this file.

When executing pcl6, you get a list of available output devices. The ones, 
that are most interesting for us are: mswinpr2 to print to a Windows printer
and pdfwrite to write to a PDF file.

  pcl6 -dNOPAUSE -dBATCH -sDEVICE=<device> -sOutputFile=<output f.> <Input f.>

-dNOPAUSE and -dBATCH are important, so that you can execute the command
in batch operation, otherwise you must confirm the page output with RETURN.

-sDEVICE= selects the output device mentioned above.

-sOutputFile= specifies either the PDF-file to write to (in case you are using
pdfwrite) or the Printer you want to print to (in case of mswinpr2 device).
If you want to select the Printer, use the syntax: \\spool\<Printername>, i.e.:
-sOutputFile=\\spool\Brother
If you don't select a printer, you will be prompted for the printer.

I added another useful option for the mswinpr2 driver:
You can specify the document name for the output via: 
-sDocumentName="Name of the document"
This may be useful if you want to print to a printer device that converts
the printer output to another format and uses the Document name as default
"Save as.." filename.

Additionally, you can add PJL options for the batch job with -J, we do so in 
pclenv.bat for example:
  -J"@PJL SET FORMLINES = 66" -J"@PJL SET PAPER=A4"
The FORMLINES PJL command specifies, that it will output 66 lines per page
as default, which seems to be necessary when printing out plain text files
to get a proper spacing.
For a list of PJL commands, have a look at the HP PJL documentation:
http://www.cyrtech.de/articles/hp.htm


Putting it all together
=======================

A simple setup:
First, capture the printer output, either by invoking PRN2FILE.COM prior
to the start of your DOS-application, or by pointing your DOS-Application
to print to C:\PRNSPL
Then use one of the 3 Batchfiles according to your needs:

escp2prn.bat	-	Simple Text output, EPSON LQ/SQ ESC/P sequences
pcl2pdf.bat	-	PCL to PDF conversion
pcl2prn.bat	-	Print PCL - output to a Windows GDI printer

When you are finished using your dos application, you may kill the watcher 
with stop.bat


Files and their usage
=====================

dospr.exe	-	Simple EPSON ESC/P printer application by me
epson.seq	-	ESC-Sequence definition file for dospr.exe
escp2prn.bat	-	Starter for printing ESC/P files to Windows printer
pcl2pdf.bat	-	Starter for printing PCL files to PDF
pcl2prn.bat	-	Starter for printing PCL files to Windows printer
pcl6.exe	-	Artifex GhostPCL, including mswinpr2 output device
pclenv.bat	-	Environment settings for GhostPCL, used by pcl2*.bat
PRN2FILE.COM	-	DOS printing redirector
stop.bat	-	Kills watcher.exe processes
urwfonts	-	Directory containing urwfonts for GhostPCL
watcher.exe	-	Little application that watches file changes
_escp2prn.bat	-	Helper for escp2prn.bat, does the real work
_pcl2pdf.bat	-	Helper for pcl2pdf.bat, does the real work
_pcl2prn.bat	-	Helper for pcl2prn.bat, does the real work


Author
------
Package compiled by Dipl.-Ing. (FH) Ludwig Ertl
mailto: ludwig.ertl@dose.0wnz.at

You can get my other useful DOS-Utilities here:
http://www.waldbauer.com/tmp/reference.php

GhostPCL and URWFONTS (c) by Artifex Software Inc.
PRN2FILE (c) by Gurtjak D., Ignatenko I., Goldberg A. 

License
-------
This Application and Sourcecode may be distributed freely.
The Sourcecode is Licensed in Terms of the GNU GPL v2.
See: http://www.gnu.org/licenses/gpl.html
URWfonts are licensed unter the AFPL:
http://www.artifex.com/downloads/doc/Public.htm

Thanks
------
Thanks to all the users who are still using DOS Applications ;)
