Are there any good code examples available for using the printer routine libraries in a managed cobol program?
Are there any good code examples available for using the printer routine libraries in a managed cobol program?
What is it that you are trying to achieve?
There are some examples in our knowledgebase (searchable from the Search field above) or on the Net Express forum. if you look for terms like "print" then you will find some specific examples of how to perform various tasks but I could not find a generic example that showed how to use all of the functionality.
Printing in .NET can also be achieved by using the PrintDocument and other classes.
I tried to create a program that would demonstrate how to get the Printer name and properties from the PrintDialog and then set them using PC_PRINTER_DEFAULT_NAME and PC_PRINTER_DEFAULT_PROPERTIES so that they would work with printer redirection and I discovered that some of the properties such as print orientation are being ignored so I wrote this up as a bug.
I am including the program here anyways. The following will attempt to set the orientation and the number of copies. You must set the tunable printer_redirection on order for this to work properly.
$set ilusing"System.Windows.Forms"
identification division.
program-id. manProgram1.
environment division.
configuration section.
select print-file assign to PRINTER
file status is file-status.
data division.
file section.
fd print-file.
01 print-rec pic x(20).
working-storage section.
78 DMORIENT-PORTRAIT value 1.
78 DMORIENT-LANDSCAPE value 2.
78 P-PAPERSIZE value 1.
78 P-PAPERLENGTH value 2.
78 P-PAPERWIDTH value 4.
78 P-SCALE value 8.
78 P-COPIES value 16.
78 P-PAPERTRAY value 32.
78 P-PRINTQUALITY value 64.
78 P-COLOR value 128.
78 P-DUPLEX value 256.
78 P-ORIENTATION value 512.
78 P-YRESOLUTION value 1024.
01 file-status pic x(2) value spaces.
01 flags pic x(4) comp-5.
01 status-code pic x(4) comp-5 value zeroes.
01 printer-properties.
03 pp-len pic x(2) comp-5.
03 pp-papersize pic s9(4) comp-5.
03 pp-paperlength pic s9(4) comp-5.
03 pp-paperwidth pic s9(4) comp-5.
03 pp-scale pic s9(4) comp-5.
03 pp-copies pic s9(4) comp-5.
03 pp-papertray pic s9(4) comp-5.
03 pp-printquality pic s9(4) comp-5.
03 pp-color pic s9(4) comp-5.
03 pp-duplex pic s9(4) comp-5.
03 pp-orientation pic s9(4) comp-5.
03 pp-yresolution pic s9(4) comp-5.
01 printer-default-name.
03 pd-printer-name-len pic x(2) comp-5.
03 pd-printer-name pic x(128).
01 Printer-RetCode pic 9(4) comp-5.
78 SET-DEFAULT-PRINTER value h"0001".
78 BROWSE-DEFAULT-PRINTER value h"0002".
01 name-len pic x(2) comp-5 value zeroes.
procedure division.
declare myprintdialog as type PrintDialog = new PrintDialog
if myprintdialog::ShowDialog not = type DialogResult::OK
stop run
end-if
move myprintdialog::PrinterSettings::PrinterName to pd-printer-name
move myprintdialog::PrinterSettings::PrinterName::Length to pd-printer-name-len
move length of printer-properties to pp-len
compute flags = p-copies p-orientation
move myprintdialog::PrinterSettings::Copies to pp-copies
if myprintdialog::PrinterSettings::DefaultPageSettings::Landscape = true
move dmorient-landscape to pp-orientation
else
move dmorient-landscape to pp-orientation
end-if
call "PC_PRINTER_DEFAULT_NAME"
using by value 1
by reference printer-default-name
returning status-code
end-call
if status-code not = 0
display "Unable to set a default printer = " status-code
stop run
end-if
call "PC_PRINTER_DEFAULT_PROPERTIES"
using by value flags
by reference printer-properties
returning status-code
end-call
if status-code not = 0
display "Unable to set printer props = " status-code
stop run
end-if
open output print-file
display file-status
move all "A" to print-rec
write print-rec
display file-status
close print-file
goback.
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.