Printing to a USB Printer and columns are not aligned



Customer has a native Visual COBOL application that is using an OPEN to a printer which is a USB printer under Windows.

They are setting the configuration option set printer_redirection=TRUE in a cobconfig.cfg file and are setting the environment variable COBCONFIG_ to point to this file.

The printer redirection is working correctly and the output from the WRITE statements is successfully be printed. The problem is that the report is supposed to be aligned in columns and these columns are not be aligned properly so they do not match up from row to row.

It prints correctly when printing to a printer attached to the LPT1 port.


Notes: Printer alignment issues on a USB printer most likely have nothing to do with COBOL and have everything to do with what is set as the default font for the printer.

If the default font is a proportional font then all characters are not the same width so depending on what characters you are printiing the columns will not line up correctly.

Example if you are printing the following: WWWWW It will be much wider than if you are printing 1111

The resolution to this is to change the default font to one that is a fixed font so that all charcaters are printed with the same width.

Courier New can be used for this.

Since you are using the printer redirection and do direct write statements to the printer you can set the font for the printer at the time it is opened by using pc_printer_redirection_proc in conjunction with pc_printer_set_font.

The following is a sample of how this can be done.

       id division.
       program-id.    printformat.       
       environment division.
       input-output section.

               select print-file assign to PRINTER
                                 organization is line sequential
                                 file status is file-status.

       data division.
       file section.
       fd print-file.
       01 print-record.
          05                 pic x(5).
          05 column1         pic x(5).
          05                 pic x(5).          
          05 column2         pic x(5).
          05                 pic x(5).       
          05 column3         pic x(5).
       working-storage section.
       01 file-status        pic x(2)  value spaces.
       01 flags              pic x(4) comp-5 value zeroes.
       01 user-func          procedure-pointer.
       01 font-family-name.
            05 font-name-len   pic x(2) comp-5 value 11.
            05 font-name       pic x(11) value "Courier New".
       01 font-size          pic x(4) comp-5 value 12.
       01 font-style         pic x(4) comp-5 value 0.       
       01 status-code        pic x(4) comp-5 value zeroes.
       local-storage section.       
       linkage section.
       01 printer-handle     pic x(4) comp-5.
       procedure division.

          set user-func to entry "user-func"

              using by value flags

           open output print-file
           display "open = " file-status
           move spaces to print-record
           move all "1" to column1 column2 column3
           write print-record            
           display "write = " file-status
           move all "W" to column1 column2 column3           
           write print-record
           display "write = " file-status
           move all "D" to column1 column2 column3
           write print-record           
           display "write = " file-status
           close print-file
           stop run.

       entry "user-func" using by value printer-handle.

           call "PC_PRINTER_SET_FONT"
              using printer-handle                  
                       by value font-size
                       by value  font-style
              returning status-code

           exit program returning status-code.


Comment List
Related Discussions