Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: Redirect LPT1?

$
0
0

The easiest method for you to write data with embedded PCL codes directly to a printer would be to first write this file to disk instead of LPT1 and then to send this file to the printer using the routine PC_PRINT_FILE. There is a flag setting in Visual COBOL whereby if you set bit 5 on it will redirect the raw data to the Windows spooler so it will send the file to whatever is currently the default printer in Windows.

You can also change the default printer using PC_PRINTER_DEFAULT_NAME.

Here is an example:

       id division.
       program-id. callprintraw.
       environment division.
       input-output section.
       file-control.
           select print-file assign to filename
                             organization is line sequential
                             file status is file-status.
       data division.
       file section.
       fd print-file.
       01 print-record  pic x(132).
       working-storage section.
       01 file-status   pic x(2)  value spaces.

      *** Change the following to your printer name.
       
       01 filename-param.
          03 filename-len          pic x(2) comp-5 value 13.
          03 filename              pic x(256) value "printfile.txt".
          
       01 document-title.
          03 document-name-len     pic x(2) comp-5 value 7.
          03 document-name         pic x(7)  value "testraw".
       01 flags                  pic x(4) comp-5 value 33.
       01 window-handle            pic x(4) comp-5 value 0.
       01 printer-status         pic x(4) comp-5  value zeroes.

       01 printer-esc-codes.
          05 reset-printer       pic x(2)         value x"1B45".
          05 page-size-legal     pic x(5)         value x"1B266C3341".
          05 page-size-A4        pic x(6)         value x"1B266C323641".
          05 portrait            pic x(5)         value x"1B266C304F".
          05 landscape           pic x(5)         value x"1B266C314F".
          05 6-lines-per-inch    pic x(5)         value x"1B266C3644".
          05 8-lines-per-inch    pic x(5)         value x"1B266C3844".
          05 underline-on        pic x(5)         value x"1B26643044".
          05 underline-off       pic x(4)         value x"1B266440".
       01 string-pointer         pic 9(3)         value 1.
       procedure division.

           open output print-file
           display "open status = " file-status

      ***  Send setup codes to printer.
           move spaces to print-record
           string reset-printer
                  page-size-legal
                  portrait
                  6-lines-per-inch
                  into print-record
                     with pointer string-pointer
           end-string
           
           write print-record
           display "write = " file-status

           move "This is Test Line Number 1" to print-record
           write print-record
           display "write = " file-status

           move spaces to print-record
           move 1 to string-pointer
           string underline-on
                  "This line should be underlined"
                  underline-off
                  into print-record
                     with pointer string-pointer
           end-string
           write print-record
           display "write = " file-status

           move "This line should not be underlined" to print-record
           write print-record
           display "write = " file-status.
           
           move spaces to print-record
           move reset-printer to print-record
                     
           write print-record
           display "write = " file-status    
       
           close print-file

           CALL "PC_PRINT_FILE" using filename-param
                               document-title
                     by value  flags
                     by value  window-handle
                     returning printer-status
           end-call

           display "printer status = " printer-status
           stop run.



Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>