Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Printing to a USB Printer and columns are not aligned

Printing to a USB Printer and columns are not aligned

Problem:

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.

Resolution:

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.
       file-control.

               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"

          call "PC_PRINTER_REDIRECTION_PROC"
              using by value flags
                             user-func
           end-call.

           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                  
                       font-family-name
                       by value font-size
                       by value  font-style
              returning status-code
           end-call

           exit program returning status-code.

 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-03-08 06:54
Updated by:
 
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.