Skip to content

SCS Reader is an OSGI compatible Java library which is able to read, parse and transform SCS (SNA Character String) data streams. The implementation also offers some converters to transform such streams into Text, PDF, RTF or other formats.

Notifications You must be signed in to change notification settings

nitram509/scsreader

Repository files navigation

SCS Reader - Documentation

Martin W. Kirst v1.0, 2011-06

Abstract

SCS Reader is an OSGI compatible Java library which is able to read, parse and transform SCS (SNA Character String) data streams. The implementation also offers some converters to transform such streams into Text, PDF, RTF or other formats. At the current state it supports all features of the SCS 5256 printer standard.

There are also renderer for Java Swing or Eclipse SWT available

Screenshot

Example of a spool file within a SWT StyledText widget

Usage

This project is designed to be an easy drop in replacement for projects with existing PDF view or export functionality. The implementation design was inspired by the Java(TM) Streaming API for XML Thus it's fast and very flexible. Additionally, one main difference to any other implementation in this area is the fact, that the SCS data streams pretty soon are converted to Unicode and further processing is all done in unicode. Therefore it's worthwhile to use this library in multilingual environments.

Example Text-Printer

import java.io.File;
import java.io.FileWriter;

import net.scs.reader.EndOfFileSignal;
import net.scs.reader.IPrinterMicroCommand;
import net.scs.reader.IScsDataProvider;
import net.scs.reader.ReaderConfig;
import net.scs.reader.SCSStreamReader;
import net.scs.reader.dataprovider.As400ScsDataProviderFactory;
import net.scs.reader.virtualprinter.PrinterConfig;
import net.scs.reader.virtualprinter.TextPrinter;

import com.ibm.as400.access.SpooledFile;

public class ExampleTextPrinter {

	public static void main(String[] args) throws Exception {
		SpooledFile spooledFile = null; // TODO: provide your spool file!                                 <1>
		final IScsDataProvider dp = As400ScsDataProviderFactory.getPrintObjectDataProvider(spooledFile);
		final ReaderConfig rcfg = new ReaderConfig.Builder()
				.collectPrintableChars(true)
				.ignoreUnknownControlCodes(false)
				.ignoreNulls(false)
				.getConfig();
		final SCSStreamReader reader = new SCSStreamReader(dp, rcfg);

		PrinterConfig pcfg = PrinterConfig.getDefault();
		TextPrinter printer = new TextPrinter(pcfg);

		try {
			while (reader.hasNext()) {
				final IPrinterMicroCommand event = reader.next();
				if (event == null) break;
				printer.runMicroCommand(event);
			}
		} catch (EndOfFileSignal e) {
			System.out.println("eof.");
		}

		printer.finish();

		FileWriter fw = new FileWriter(new File("test.txt"));
		printer.writeText(fw);
		fw.close();
	}
}

Example PDF-Printer

import java.io.FileOutputStream;

import net.scs.reader.EndOfFileSignal;
import net.scs.reader.IPrinterMicroCommand;
import net.scs.reader.IScsDataProvider;
import net.scs.reader.ReaderConfig;
import net.scs.reader.SCSStreamReader;
import net.scs.reader.dataprovider.As400ScsDataProviderFactory;
import net.scs.reader.virtualprinter.PdfPrinter;
import net.scs.reader.virtualprinter.PrinterConfig;

import com.ibm.as400.access.SpooledFile;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

public class ExamplePdfPrinter {

	public static void main(String[] args) throws Exception {
		SpooledFile spooledFile = null; // TODO: provide your spool file!                                 <1>
		final IScsDataProvider dp = As400ScsDataProviderFactory.getPrintObjectDataProvider(spooledFile);
		final ReaderConfig rcfg = ReaderConfig.getDefault();
		final SCSStreamReader reader = new SCSStreamReader(dp, rcfg);

		PrinterConfig pcfg = PrinterConfig.getDefault();
		float FONT_SIZE = 9.0F;
		float leading = FONT_SIZE * 1.05F;
		
		// calculate font, font size, and margins for the PDF
		final Font monoSpacedFont = FontFactory.getFont(BaseFont.COURIER, FONT_SIZE);
		final Font monoSpacedFontBold = FontFactory.getFont(BaseFont.COURIER_BOLD, Font.BOLD);
		Rectangle pageSize = new Rectangle(PageSize.A4);
		final Document pdfdoc = new Document(pageSize);

		final FileOutputStream fos = new FileOutputStream("test.pdf");
		final PdfWriter pdfwriter = PdfWriter.getInstance(pdfdoc, fos);
		pdfdoc.open();
		
		PdfPrinter pdfprinter = new PdfPrinter(pcfg, pdfdoc, monoSpacedFont, monoSpacedFontBold, leading);
		
		try {
			while (reader.hasNext()) {
				final IPrinterMicroCommand event = reader.next();
				if (event == null) break;
				pdfprinter.runMicroCommand(event);
			}
		} catch (EndOfFileSignal e) {
			System.out.println("eof.");
		}
		
		pdfprinter.finish();
		pdfdoc.close();
		pdfwriter.close();
	}

Development

Project Setup

SCS Reader was developed using Eclipse IDE. Thus, the two plugins "net.scs.reader" and "unittest.net.scs.reader" are independent Eclipse projects.

Requirements

  • Java v1.6+
  • GIT, recommended as Eclipse-Plugin and command line tool
  • Eclipse Helios (v3.6+)

Dependencies

NOTE: iText newer version 5.x is not yet supported

Setup required libraries within Eclipse

  1. You have to download the required libraries
  2. Create a new java project called +wrapper-req-libs+
  3. Create a new folder +lib+ within project +wrapper-req-libs+
  4. Copy +iText.2.1.7.jar+ and +jt400.jar+ into the +lib+ folder
  5. Go to properties of the wrapper project, go to 'build path' and go to 'order and export'
  6. Check the two named libraries so that they get exported
  7. Right-Click the wrapper project, click 'Configure' and click 'Convert to Plug-in projects'

Once you've converted the requiered 'JARs' into a plugin project, your workspace should be error free and you should be able to start hacking on this project.

Additional Documentation

Feature sets per printer type, ordered/shown in hierarchical order

About

SCS Reader is an OSGI compatible Java library which is able to read, parse and transform SCS (SNA Character String) data streams. The implementation also offers some converters to transform such streams into Text, PDF, RTF or other formats.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published