How to print from BASIC DOS to any Windows printer


This article applies to the Basic programming language and its DOS variations (GWBasic, QuickBasic, PowerBasic, etc.) covering 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.)

Basic printing

DOS Basic programs are used to print by using LPRINT statements, which directly send the specified characters to the LPT1: (only) 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 causes a common problem: The DOS print job starts after a long time or only when closing the Basic program. That's because LPRINT does not close the printer port at the print job end.

Fortunately, the Basic language already provides a solution for this problem. Consider this source:

  10 LPRINT "Hello world"

You can obtain the same behaviour changing it as:

  20 PRINT #1,"Hello world"
  30 CLOSE #1

with two main advantages:
  1. You can specify a different port in line 10, like LPT2:, LPT3:, or even a FILE on disk.
  2. You've closed the printer port at the print job end, making your jobs immediately spooled by Windows.
Practically, you only need to add the OPEN command at the beginning of each job and the CLOSE command at the end, then each "LPRINT" statement should be changed as "PRINT #1,", which can be done with a simple Search & Replace editor tool.

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

Basic cannot directly address USB, DOT4 and other Windows ports which were not available in the age of DOS, so you cannot insert them in Line 10. 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 Basic (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:

  10 D$="c:\basic\printfil.txt"
  20 REM D$="LPT1:"
  40 PRINT #1,"Hello world"
  50 CLOSE #1

Depending by whether line 20 is commented (REM) or not, you can make your Basic program printing directly to the LPT1 port (just like LPRINT) or to a file on disk. Now you just have to insert "c:\basic\printfil.txt" in the "File to check" field of the Printfil's configuration dialog to have Printfil automatically capturing your Basic 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  
  17 Nov 2016  
  New Printfil 5.21
What's new
Print from DOS to USB printer now! Download free PrintFil trial!
  Click here to see the most Frequently Asked Questions  
  see also ...  
  File In Mail: Automatically send out files via email