Highlighted
Absent Member.
Absent Member.
1979 views

StreamReader forcing a page advance

Jump to solution

Using the demo you provided in another post (PrintTextVC.sln), I am able to pass the report location etc. to my printing pgm and successfully print the file.  The issue I have is that the StreamReader doesn't honor the page breaks in the file.  Is it possible to evaluate the lines being read and if I see 'Page:' for example, force it to advance a page? 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: StreamReader forcing a page advance

Jump to solution

If you simply want to print a text file that you have already created then I would suggest that you use the Visual COBOL Library routine PC_PRINT_FILE.

In Visual COBOL 2.0 we have added a new flag to PC_PRINT_FILE which allows you to send the file as RAW data so you can have embedded control characters (PCL) in your file and they will be sent to the print spooler as is.

PC_PRINT_FILE is documented here

The following is a sample which creates a text file with embedded control characters and then sends it to the default printer.

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.

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: StreamReader forcing a page advance

Jump to solution

If you simply want to print a text file that you have already created then I would suggest that you use the Visual COBOL Library routine PC_PRINT_FILE.

In Visual COBOL 2.0 we have added a new flag to PC_PRINT_FILE which allows you to send the file as RAW data so you can have embedded control characters (PCL) in your file and they will be sent to the print spooler as is.

PC_PRINT_FILE is documented here

The following is a sample which creates a text file with embedded control characters and then sends it to the default printer.

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.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: StreamReader forcing a page advance

Jump to solution

Thanks.  That's what we use in Net Ex 3.1 so I've got one I can use.  Good information.

Bud

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.