Created On:  18 May 2012

Problem:

How do I write to a printer on Windows when my text includes embedded Printer Control Codes (PCL) and ESC sequences?

I have tried using the run-time tunable printer_redirection=TRUE to redirect output to the Windows Print Spooler but when I use these ESC sequences they are being stripped out and I am not getting the formatting that I expect.

How can I write to a Windows printer that is not attached to LPT1 and have the printer recognize my PCL codes?

Resolution:

There is a new run-time tunable introduced in Visual COBOL 2.0 that provides for this capability in managed code .NET programs.
It is called printer_raw_redirection and it can be used in conjunction with printer_redirection to allow you to write directly to a Windows printer and still use your embedded PCL codes.

See the attached example program called testprintraw.

Here is the description of this example:

TESTPRINTRAW

This sample program demonstrates the capability of printing "raw" data to a printer under Windows.
This is a new feature of Visual COBOL 2.0
and is supported for managed code only.
This feature is enabled by
adding the following two run-time tunables to the managed code

app.config file of your project:

    add key="printer_redirection" value="true"
    add key="printer_raw_redirection" value="true"

The printer_redirection tunable by itself causes all output sent to a file defined as PRINTER in the select statement to be redirected to the Windows Print Spooler. This output will then be sent to whatever is defined as your default printer under Windows. A different printer can also be selected by adding the following tunable to app.config: 

    add key="printer_defaults" value="printer.name=\\mypc\myprinter"

The printer name can also be selected dynamically by using the library routine PC_PRINTER_SET_DEFAULT.

When setting the printer_raw_redirection tunable also, data will be sent to the default printer as "RAW" data which means you can embed Printer Control Language (PCL) esc sequences directly in your text in order to control advanced printer features and formatting on printers that support PCL.

The attached sample will open the default printer and send a couple of lines of formatted text to be printed.
If you wish to dynamically set
the printer name then uncomment out the perform to the 100-set-default-printer paragraph and provide your printer name in the pd-printer-name variable in working-storage.

The support for printing RAW data is only enabled in managed code .NET programs and is not supported directly in native programs.

Also see PC_PRINT_FILE documentation for use with new RAW printing flag.