How to print from Clipper DOS to any Windows printer

Introduction

This article talks about the Clipper programming language, but applies also to other xBase variants (like dBase for example), and covers different topics about how to correctly manage Windows printing:
  1. Closing the printer port at the print job end
  2. Printing to printers which are not DOS compatible, like USB GDI printers or virtual printers (fax printer drivers, PDF writers, etc.)

Clipper printing

DOS Clipper programs by default were designed to print a data flow (a sequence of characters) directly to the PRN device, which is the LPT1: parallel port.

In the age of DOS, typically a dot-matrix printer was connected to LPT1:, starting printing that data as soon as it was sent to the port and before all the data has been sent by the program, but on recent Windows systems this may cause a common problem: The DOS print job starts after a long time or only when closing the Clipper program. If that happens to you too, then it's because your Clipper program does not close the printer port at the print job end.

Fortunately, the Clipper language already provides a solution for this problem:

  SET DEVICE TO PRINT
  SET CONSOLE OFF
  SET PRINTER ON
  SET PRINTER TO LPT1  
  ...
  ... @ x,y say ...
  ...
  SET PRINTER OFF
  SET CONSOLE ON
  SET DEVICE TO SCREEN
  SET PRINTER TO


The last line closes the printer port. In addition,
you can specify a different port in the 4th line, like LPT2, LPT3, or even a FILE on disk.

On some Windows systems, a single SET PRINTER TO at the print job end is not sufficient to definitely solve the problem. In this case you may also insert a call the function below, after the last SET PRINTER TO.

  FUNCTION Close-PRN()
  Local cPort := set(24,"LPT3") // Current DOS port
  set(24,"LPT2")
  set(24,"LPT1")
  set(24,"" )
  set(24,cPort,.t.)
  Return Nil

 
So far you've solved one of your problems, but you still need a DOS compatible printer connected to the port specified in the 4th line of the top sample.

Clipper cannot directly address USB, DOT4 and other Windows ports which were not available in the age of DOS, so you cannot insert them in the 4th line. In addition, more and more printers nowadays are GDI (also known as Windows-Only or host-based printers), which cannot be driven by a DOS program neither if they are connected to LPT1: or if you forward the LPT1: output to one of the ports above with a simple redirection utility like the NET USE Windows command.
These aspects are covered in detail in the article: How to print from DOS to USB Windows-Only printers.

So, you need a Windows program like Printfil to capture the Clipper (DOS) print job, convert it into a GDI (Windows) job, THEN forward it to one of the above printers.

Printfil can be configured to capture the LPT output itself, but as a programmer you may want to change the sample source above as follows:

  SET DEVICE TO PRINT
  SET CONSOLE OFF
  SET PRINTER ON
  SET PRINTER TO ("c:\clipper\printfil.txt")  
  ...
  ... @ x,y say ...
  ...
  SET PRINTER OFF
  SET CONSOLE ON
  SET DEVICE TO SCREEN
  SET PRINTER TO


This change in the 4th line makes your Clipper program printing directly to a file on disk. Now you just have to insert "c:\clipper\printfil.txt" in the "File to check" field of the Printfil's configuration dialog to have Printfil automatically capturing your Clipper print jobs and forwarding them to any printer installed
in your Windows Control Panel (including USB, GDI, DOT4 and virtual printers), without having to configure it to capture the LPT1: output.

  Articles Home  
  Other articles about DOS and Windows printing  
   
   
   
   
  10 Jul 2014  
  New Printfil 5.18
What's new
 
Print from DOS to USB printer now! Download free PrintFil trial!
  FAQ  
  Click here to see the most Frequently Asked Questions  
  see alo ...  
  File In Mail: Automatically send out files via email