Example: Create SCS Spooled File

Example application that generates a SCS data stream, using the SCS3812Writer class, and writes it to a spooled file on the AS/400.

This application can take two arguments:

  1. Name of the AS/400 to receive the spooled file.
  2. Name of the outque on the AS/400 to receive the spooled file.

Or it can use the defined defaults.

For more information about AS/400 Printing, refer to:

  • OS/400 Printer Device Programming, SC41-3713
  • IBM AS/400 Printing IV Redbook, GG24-4389
/////////////////////////////////////////////////////////////////////////
//
// This source is an example of AS/400 Toolbox for Java "SCS3812Writer".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind.  The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// AS/400 Toolbox for Java
// (C) Copyright IBM Corp. 1997
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
/////////////////////////////////////////////////////////////////////////

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 AS/400 Java Toolbox.");
            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);
        }
    }
}