home
products
education
support
partners
company

introduction

get started

articles

manual

tutorials

reference docs

case studies

knowledge base

goodies

screenshots

demos

echoes

Carousel zone




home

forums

downloads

bugs

mailing list
XUI Zone - manual

number of ratings 0
average rating 0.00

29 Printing

[This is a feature of Carousel]

Printing an Carousel application with Java is a little more complicated than using XML by its very nature. Printouts can be produced in a number of different ways, directly and indirectly through applications like Excel and OpenOffice.

Direct printing

Carousel's pages can be printed directly using the built-in infrastructure. However it should be noted that this may not be appropriate in all situations. A page created for on-screen, landscape rendering may not be best suited to the high resolution, portrait format of most printers. Carousel applications can also include special printout pages where the layout and aspect can be given a more suitable configuration. Using the data binding schemes promoted by Carousel this should involve little additional work while at the same time adding versatility to the printout infrastructure.

The printing infrastructure

Printing in Carousel uses the normal Java printing API and mechanisms, but in order to hide some of the low level details Carousel provides some additional infrastructure. The printing infrastructure revolves around three classes in the com.xoetrope.print package. These classes are:

Code Sample 29-1 - The Printing Classes

Printout

This class encapsulates the print job. Control of headers and footers is also provided.

PrintablePage

A decoration of the XPage class to support printing. Scales the page as needed.

PrintableFrameSet

A decoration of a frameset to allow printing of the frameset's pages. Again scaling is performed as needed.

These classes act as decorations of the XPage class so that the pages can be configured for on-screen use or for printing or they can be used for both purposes. This decoration also means that the pages can be designed as any other page with little need for special considerations.

The use of thse classes are as follows:

Code Sample 29-2 - Printing a Frameset

/**

* On a mouse click print this page

*/

public void printPage()

{

// Hide the navigation buttons for the home page

if ( wasMouseClicked() ) {

Printout po = new Printout();

po.showPageFormat();

po.setJobName( "Survey Printout" );

po.setHeader( "Left Header", Printout.LEFT );

po.setHeader( "Right Header", Printout.RIGHT );

po.setFooter( "Footer", Printout.LEFT );

po.setPageNumbers( false, Printout.RIGHT, "Page " );

int numFrames = pageManager.getNumTargets();

PrintableFrameSet pf = new PrintableFrameSet( po );

for ( int i = 0; i < numFrames; i++ )

pf.addFrame( pageManager.getTarget( i ) );

po.addFrame( pf );

po.print();

}

}

Creating print forms

Printing tables

Controlling the printer

Other printout issues

While most of the time little by way of special consideration needs too be given to printing there are a few issues worth considering when preparing content.

Code Sample 29-3 - Printing Content Issues

Graphics

The resolution of printers is typically in thousands of dots per inch (dpi) whereas on-screen resolution is of the order of 72 dpi. An unscaled raster graphic that works well on screen will appear tiny on a printout and while Carousel scales images it cannot (in most cases)increase the image resolution and so the printed quality of the image may suffer.

The solution to this problem is to use 'lossy' raster graphics like JPEG that can interpolate the image or to use vector graphics like SVG that are ideal for scaling.

Tables

Tables frequently scroll or have varying amounts of content and this is not ideal for printing. At best a printout can accomodate vertical scrolling, but horizontal scrolling can rarely be accomodated well. When using tables pay special attention to testing with a variety of data.

Aspect

As has been noted above the resolution and aspect of the printed page normally differs from on-screen resolution. Consider using special print-only pages to accomodate your printouts. The print-only page can derive from the same class as the on-screen equivalent so any support functions and data binding can be reused.

Printing via Excel

Carousel includes a set of wrapper classes to ease the use of Excel sheets. While Excel worksheets have many potential uses they can be used for printing purposes with the sheet being created directly or with a preprepared sheet acting as a template. Carousel also includes classes to allow you easily launch Excel to preview the 'printout' prior to actual printing.

Printing and interacting with OpenOffice

OpenOffice can be used in much the same way as Excel however OpenOffice provides some extra programming control and support that can be useful in some situations.

OpenOffice can be run in a server mode where the worksheet is generated or populated by a server. This opens up the possibility of doing some sorts of workflow.

Printing via HTML

HTML provides another option for printing. Carousel includes support for printing things such as forms and tables to HTML. However because of the wide variety of formats that could be generated you should be prepared to manually code some of the HTML generation.

comments


If you were logged in you could rate this article or add a comment.