REBOL for COBOL programmers
Date written: May 27, 2014
This explains some ways that printing can be accomplished in REBOL. Printing is not as simple as in COBOL where printing reports is a core function.
COBOL was practically designed for printing because of its business orientation. When COBOL was popular, so were large printed reports printed on line printers with a fixed number of fixed-width characters in a print line. In COBOL you specify a print file by means of the SELECT statment and ASSIGN that file to PRINTER. Then you define one or more fixed-format lines of data and write them to the print file, and when you close the file the report starts coming out on the printer.
REBOL printing ideas
REBOL does not have the concept of a print file. There are not REBOL functions specifically for putting words on paper. But there are ways.
There is a REBOL module called PDF Maker. It can be found on the rebol.org web site. It is a dialect where you build up a dialect that describes pages in a PDF file and then when you process that dialect you get a PDF file. We are not too familiar with that here, at this time, so you would be on your own for investigating. The business programming documentation by Nick Antonnacio has information also.
If you don't need distinct pages with headings and page numbers, a very handy way to handle printing is to put a report into a web page. You have to build up in memory a string that is a single html page. You emit the proper html heading and footing code, and then, for each "print line," you create either a line of fixed-format text that will be inside "pre" tags, or a single row of an html table. When you "close" the html "print file" by writing the html code to disk, you then display it with a browser and use the browser's printing function to do the printing. A sample of this approach is showm in the code samples linked below.
Printing in a fixed an known environment
If you are working in a situation where the environment is known and fixed, you might be able to take advantage of that. For example, if you have all HP printers on a Windows network, you could build up a "report" in memory and then write it to the printer by means of the "write/binary" function writing to the printer server. You could control the look of the report through embedded PCL escape sequences. A sample of this approach is showm in the code samples linked below.
Left-clicking a link below will give a result that will depend on your computer, your browser, and maybe in whether or not you have REBOL installed. You should get either a new window with the code displayed, or a dialog box for saving the file on your own computer, or "opening" the file which makes no sense in this situation. Right-clicking should give you a menu from which you can save it to your own computer.
Generating an html page
This sample is a module that provides functions that wrap your "print lines" in the appropriate html tags to create an html page that will display in a browser. You then would use the browser to do the printing.
Writing to a network printer
This sample is a module that provides functions to wrap your "print lines" in appropriate PCL escape sequences so that you can "write" a string of print lines to a printer through a network print server.