Highlighted
Absent Member.
Absent Member.
1532 views

[archive] Windows Printing

[Migrated content. Thread originally posted on 20 August 2004]

Guys,

How do I send control codes to a windows printer?

I'm new to all this, so please excuse me if this is a stupid question.

For what its worth, previously in unix, we just have the relevant hex control codes inside the print file.

Now we're using the windows spooler, it just appears to do its best in printing the characters out!

Regards,

Shaun
0 Likes
3 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Windows Printing

You have to print to the device "-P SPOOLER-DIRECT".
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Windows Printing

Another tip, if you are in the process of porting reports from Unix (or any other non windows environment) to Windows, check out the -Q option.

Say you have a printer named HP Deskjet IX.

Say you want to print Courier New, 10 pitch, 66 lines 132 cols landscape mode.

Say you in your select statement uses PRINTER1.

Then you could put the following in your configuration file:

PRINTER1 -Q HP Deskjet IX;FONT=Courier New;PITCH=10;LINES=66;COLS=132;ORIENTATION=LANDSCAPE


Which would make your report print just nicely on your nearest windows printer.

How do I get the printer name? You could either use the prndemox.cbl in your template directory, or else:

       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  EnumPrinters.
       ENVIRONMENT                  DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.

       FILE-CONTROL.
       SELECT EnumPrinter           ASSIGN TO "Printerlist.txt"
           ORGANIZATION             IS LINE SEQUENTIAL.

       FILE SECTION.
       FD EnumPrinter.
       01 EprintRec                 PIC X(100).

       WORKING-STORAGE SECTION.

       01  PRINTERNNN.
           03 FILLER                PIC X(07) VALUE "PRINTER".
           03 PrinterNo3            PIC 9(3).
           03 FILLER                PIC X(4) VALUE " -Q ".
           03 FILLER                PIC X(1) VALUE x"00".

       01  PRINTERNN.
           03 FILLER                PIC X(07) VALUE "PRINTER".
           03 PrinterNo2            PIC 9(2).
           03 FILLER                PIC X(4) VALUE " -Q ".
           03 FILLER                PIC X(1) VALUE x"00".

       01  PRINTERN.
           03 FILLER                PIC X(07) VALUE "PRINTER".
           03 PrinterNo1            PIC 9(1).
           03 FILLER                PIC X(4) VALUE " -Q ".
           03 FILLER                PIC X(1) VALUE x"00".

       77  CALL-RESULT              SIGNED-INT VALUE 0.
       78  WINPRINT-GET-PRINTER-INFO-EX VALUE 28.
       77  TmpStr                   PIC X(15).

       01  WINPRINT-SELECTION.
           03  WINPRINT-NAME                   PIC X(80).
           03  WINPRINT-PORT                   PIC X(80).
           03  WINPRINT-DRIVER                 PIC X(80).
           03  WINPRINT-DRV-VERSION            SIGNED-INT.
           03  WINPRINT-NO-OF-PRINTERS         SIGNED-SHORT.
           03  WINPRINT-IS-DEFAULT             SIGNED-SHORT.
           03  WINPRINT-COPIES                 SIGNED-SHORT.
           03  WINPRINT-ORIENTATION            SIGNED-SHORT.
           03  WINPRINT-QUALITY                SIGNED-SHORT.
           03  WINPRINT-CURR-ORIENTATION       SIGNED-SHORT.
           03  WINPRINT-CURR-COPIES            SIGNED-SHORT.
           03  WINPRINT-DUPLEX                 SIGNED-SHORT.
           03  WINPRINT-COLLATE                SIGNED-SHORT.
           03  WINPRINT-COLOR                  SIGNED-SHORT.
           03  WINPRINT-CURR-DUPLEX            SIGNED-SHORT.
           03  WINPRINT-CURR-COLLATE           SIGNED-SHORT.
           03  WINPRINT-CURR-PAPERSIZE         SIGNED-SHORT.
           03  WINPRINT-CURR-TRAY              SIGNED-SHORT.
           03  WINPRINT-CURR-COLOR             SIGNED-SHORT.
           03  WINPRINT-JOB-TITLE              PIC X(80).

       PROCEDURE   DIVISION.
       MAIN SECTION.
       MAIN-001.

           OPEN    OUTPUT           EnumPrinter.
           INITIALIZE            WINPRINT-SELECTION.
           MOVE    1                TO WINPRINT-NO-OF-PRINTERS.
           CALL    "WIN$PRINTER"    USING
                   WINPRINT-GET-PRINTER-INFO-EX
                   WINPRINT-SELECTION
                   GIVING           CALL-RESULT.

           PERFORM UNTIL        CALL-RESULT NOT > 0
                   IF               CALL-RESULT
                                    EXIT PERFORM CYCLE
                                    END-IF
                   INITIALIZE       EPrintRec
                                    TmpStr
                   PERFORM          NUMBER-IT
                   INSPECT          WINPRINT-NAME REPLACING TRAILING
                                    SPACES BY LOW-VALUES
                   STRING           TmpStr
                                    WINPRINT-NAME DELIMITED BY
                                    LOW-VALUES
                                    INTO EPrintRec
                   WRITE            EPrintRec
                   ADD              1 TO WINPRINT-NO-OF-PRINTERS
           CALL             "WIN$PRINTER" USING
                                    WINPRINT-GET-PRINTER-INFO-EX
                                    WINPRINT-SELECTION
                                    GIVING CALL-RESULT
                                    END-CALL
                   END-PERFORM.
           CLOSE   EnumPrinter.
           STOP    RUN.

       MAIN-900.
       MAIN-EXIT.
           EXIT.

       NUMBER-IT SECTION.
       NUMBER-IT-001.

           MOVE    WINPRINT-NO-OF-PRINTERS TO
                   PrinterNo3
                   PrinterNo2
                   PrinterNo1.

           IF      WINPRINT-NO-OF-PRINTERS
                   MOVE             PRINTERN TO
                                    TmpStr
           ELSE IF WINPRINT-NO-OF-PRINTERS
                   MOVE             PRINTERNN TO
                                    TmpStr
           ELSE
                   MOVE             PRINTERNNN TO
                                    TmpStr
                   END-IF.

       NUMBER-IT-900.
       NUMBER-IT-EXIT.
           EXIT.


You should remove your escape sequences using this technique, but then you would be 100% printer independent as well. On the other side, say you absolutely need to use the escape sequences, you can do this, but then lack all functionality except setting printer:


PRINTER1 -Q HP Deskjet IX;DIRECT=ON


You can also set the number of copies, like:

COPIES=nnn
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Windows Printing

Thanks Gisle,

I can't get away from control codes in this case.

It because of point of sale receipt printers. I need to tell the stupid printer to cut the paper and open the cash drawer.

Why it cant do this all by itself after it stops receiving data is beyond me.....anyway

Thanks,

Shaun
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.