This example uses the SCS3812Writer class to generate an SCS data stream and write it to a spooled file on the server.
This application can take the following arguments, or it can use the defined defaults:
///////////////////////////////////////////////////////////////////////// // // This source is an example of IBM Toolbox for Java "SCS3812Writer". // ///////////////////////////////////////////////////////////////////////// import com.ibm.as400.access.*; class NPExampleCreateSCSSplf { private static final String DEFAULT_SYSTEM = new String("RCHAS1"); private static final String DEFAULT_OUTQ = new String("/QSYS.LIB/QUSRSYS.LIB/PRT01.OUTQ"); public static void main(String [] args) { try { AS400 system; SpooledFileOutputStream out; PrintParameterList parms = new PrintParameterList(); SCS3812Writer scsWtr; // Process the arguments. if (args.length >= 1) { system = new AS400(args[0]); // Create an AS400 object } else { system = new AS400(DEFAULT_SYSTEM); } if (args.length >= 2) // Set the outq { parms.setParameter(PrintObject.ATTR_OUTPUT_QUEUE, args[1]); } else { parms.setParameter(PrintObject.ATTR_OUTPUT_QUEUE, DEFAULT_OUTQ); } out = new SpooledFileOutputStream(system, parms, null, null); scsWtr = new SCS3812Writer(out, 37); // Write the contents of the spool file. scsWtr.setLeftMargin(1.0); scsWtr.absoluteVerticalPosition(6); scsWtr.setFont(scsWtr.FONT_COURIER_BOLD_5); scsWtr.write(" Java Printing"); scsWtr.newLine(); scsWtr.newLine(); scsWtr.setCPI(10); scsWtr.write("This document was created using the IBM Toolbox for Java."); scsWtr.newLine(); scsWtr.write("The rest of this document shows some of the things that"); scsWtr.newLine(); scsWtr.write("can be done with the SCS3812Writer class."); scsWtr.newLine(); scsWtr.newLine(); scsWtr.setUnderline(true); scsWtr.write("Setting fonts:"); scsWtr.setUnderline(false); scsWtr.newLine(); scsWtr.setFont(scsWtr.FONT_COURIER_10); scsWtr.write("Courier font "); scsWtr.setFont(scsWtr.FONT_COURIER_BOLD_10); scsWtr.write(" Courier bold font "); scsWtr.setFont(scsWtr.FONT_COURIER_ITALIC_10); scsWtr.write(" Courier italic font "); scsWtr.newLine(); scsWtr.setBold(true); scsWtr.write("Courier bold italic font "); scsWtr.setBold(false); scsWtr.setCPI(10); scsWtr.newLine(); scsWtr.newLine(); scsWtr.setUnderline(true); scsWtr.write("Lines per inch:"); scsWtr.setUnderline(false); scsWtr.newLine(); scsWtr.write("The following lines should print at 8 lines per inch."); scsWtr.newLine(); scsWtr.newLine(); scsWtr.setLPI(8); scsWtr.write("Line one"); scsWtr.newLine(); scsWtr.write("Line two"); scsWtr.newLine(); scsWtr.write("Line three"); scsWtr.newLine(); scsWtr.write("Line four"); scsWtr.newLine(); scsWtr.write("Line five"); scsWtr.newLine(); scsWtr.write("Line six"); scsWtr.newLine(); scsWtr.write("Line seven"); scsWtr.newLine(); scsWtr.write("Line eight"); scsWtr.newLine(); scsWtr.endPage(); scsWtr.setLPI(6); scsWtr.setSourceDrawer(1); scsWtr.setTextOrientation(0); scsWtr.absoluteVerticalPosition(6); scsWtr.write("This page should print in portrait orientation from drawer 1."); scsWtr.endPage(); scsWtr.setSourceDrawer(2); scsWtr.setTextOrientation(90); scsWtr.absoluteVerticalPosition(6); scsWtr.write("This page should print in landscape orientation from drawer 2."); scsWtr.endPage(); scsWtr.close(); System.out.println("Sample spool file created."); System.exit(0); } catch (Exception e) { // Handle error. System.out.println("Exception occured while creating spooled file. " + e); System.exit(0); } } }