Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
TDMWeb Kylix Developer's Guide
 Component review: JClass PageLayout 4.0 for Java 2
See Also: JBuilder Papers

Description: JClass PageLayout offers Java developers a set of methods and procedures for adding paginated, formatted, flowed-text, and image output to Java applications.
Price: $399 ($1299 with source code)
Requirements: Java 2 version needs JDK 1.2.2
JDK 1.1 version needs JDK 1.1.8 and Swing 1.1.1

Printing isn't easy in Java. Although printing support has been improved in Java 2, we still must do very basic graphics programming to get something readable to the printer. For example we must define at pixel level what we want to print!

So it would be nice if we could use a library of classes, which takes printing to a higher level. And that is where JClass PageLayout 4.0 for Java 2 from KL Group comes into play. The PageLayout classes put an abstract layer on top of the Java 2 printing API, which makes printing a lot easier.

From document, to page, to frame, to flow
PageLayout divides the document up into different parts. A document object consists of page objects, page objects consist of frame objects and frame object consist of flow objects. We can create this objects in our applications and create a printer object to which the document will be attached. The actual text, graphics or tables will be added to the flow object, and at the end we can invoke a print() method on the document and the document including the pages and what is on them is sent to the printer.

Documents are defined using templates written in XML. Pre-installed we have got simple document templates for letter and A4 (the A4 format didn't work on my machine) format, but it is very easy to create our own templates with XML. This way we can define different formats for different pages in our document. For example the format of the cover page will be different than for the table of contents page.

We can also define header and footers for the document, because they are nothing more or less than frames we have to define. And we can include things like a page number on every page and use section numbers for headings.

We can define styles for the format of our text. This way we can define for example a header style and a normal style, which can be changed easily. Tabs, indents and columns are supported by PageLayout. PageLayout uses the normal Java fonts for generating the text. Using only the Java fonts seems like a limitation, but this way we are sure we develop 100% pure Java applications. It is possible to use other fonts, but then we must use Adobe font definitions and include them with our application.

Inclusion of images is very easy: we simply create an image object and we can add it anywhere in our text. Even Swing icons can be embedded into the document.
It is also possible to include java.awt.Component (and descendants) in the document. But this doesn't work all the time (as mentioned in the readme file). I could for example not include a Button component.

Tables are separate objects we must create. We can populate the table in different ways:

And of course we can set border properties, create header and define printing behaviour when the table is bigger than the page. Using the table and other features we can create reports with data from a database.

Paper, PDF, PCL, Postscript, screen?
PageLayout makes it possible to not only print to paper, but also to screen and create a Swing-based preview window. I experienced some problems with printing to the printer (lines printed only half), but that can be a problem of the JDK and my printer. But that is not all! We can also print to files in the following formats: PDF, Postscript and PCL. We simply have to create the corresponding printer object and we are done. We don't have to change anything else in our application. It would have been nice if HTML was included, but then again, HTML is straight forward text so we can do it ourselves.

Java 1.1 support
The JClass PageLayout classes are also available in a JDK 1.1 version, but then the support for printing to a printer, screen and previews are not included, because of JDK 1.1 printing limitations.

Conclusion
Printing has become more mature in Java. JClass PageLayout is a library for programming printing capabilities in our Java applications. It is not a visual report designer, it is a set of classes we can use in our developing process. This extra layer on top of the printing API makes it much easier to include printing capabilities in our Java applications.
And the possibility of printing to files with PDF, Postscript and PCL format is great, because it makes exchanging documents and reports easier.

If we have to include printing capabilities often in our applications we can save a lot of time by using PageLayout.


This webpage © 1997-2010 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.