Fog Creek Software
Discussion Board




Java Printing questions

Hi,

I am upgrading an application from xbase++ to Java. In order do this I am converting the printing side first.

The current xbase++ application still prints using Escape codes to lpt1, lpt2 etc..

I am writing the "Print server" in Java. The idea is that the xbase++ app can output an XML file which contains all the data to print, the print server will scan a directory, pick the file up and produce the print out. This software will not be thrown away when the rest of the app is completed.

The XML file will contain what printout to do i.e. quotation, order etc..

The problem I am having is finding some printing software that is capable enough.

Most of the printouts will be reports but there are 4 which are form letters.

I have a note block that gets printed, but I need to be able to specify that if the block is under 10 lines and won't all fit on the page, then the printout should page eject  and then print the rest.

Or to print as much as it can then break and print a nice. 'Additional information continued..' type banner.

These printouts do not ideally fit into a header, body footer layout  i.e. page 2 may have different things printed to page one.

Most report writers will not handle the page breaking stuff or at least none that I have found.

So some questions/requirements

1) I don't really want a programming API type library unless it comes with layout creation tools. The printouts will need to be customisable on a customer by customer basis.

2) Will Crystal Reports do this and can I call the API from Java? ( I know it handles forms based reports but it only runs on windows. I really want a cross platform solution).

3) Can I use the Open Office SDK and will that allow the pagination decisions i.e. be driven by code or is it worth only using it for placeholders/templates.


I have found that printing is probably the most complicated part of programming. I would be very interested to hear how others handle printing that is more complicated than the standard report layout.

Most printouts I have seen on the net are all single page based reports.

Regards

Mike Grace
Tuesday, September 16, 2003

Typo. I mean if a page only has 10 lines left then it should eject and print all 10 lines on the following page.

Mike Grace
Tuesday, September 16, 2003

I'm not sure this is what you are looking for but have you considered using XSL to convert your XML to XSL-FO and from there using the open source project FOP (from apache.org) to convert it to PDF and then printing?

Name withheld out of cowardice
Tuesday, September 16, 2003

Why transform 2 times?

Why app -> XML -> printer  (2 transformations) ?

Why not directly: app -> printer (1 transformation) ?

Most decent development tools have a reporting system: Crystal Reports, QuickReport, Rave Reports, etc.

Jack Thybolt
Tuesday, September 16, 2003


I think I had better looks those terms up. I have never seen so many Three letter abreviations (TLA) that I don't understand in one sentence!

.. Only joking ;-)

Mike Grace
Tuesday, September 16, 2003

The reason for the 2 stage transformation is because I need to give the current xbase++ application the printing ability that  the java app will have but I don't want to write some code now and dump it later.

I can't call Java directly from xbase++

I hope this makes sense.


Regards

Mike Grace
Tuesday, September 16, 2003

Mike,

It looks like XSL is what you want.

http://www.w3schools.com/xsl/

XSL is a transformation language for converting XML from one schema to another, although it is flexible enough to output to any format (though binary formats are extremely challanging).

You could use XSL to produce a text stream with escape characters, like you have now.

If HTML is good enough, you could produce the reports in HTML very easily.

If you need total control then there is FOP, which gives you complete control over the output but is very complicated.

There are several XSL libraries available.

http://xml.apache.org/

For now, you could write a Java command line utility for applying the xsl to the xml produced by DBase.

Ged Byrne
Tuesday, September 16, 2003

My approach would be to create the templates in RTF using a word processor. The RTF files are easily templated using a text processing language (eg., velocity).

Following that you need to print the output. The swing library has support for RTF (extends JEditorPane implements Printable, i think) which might do the trick.

Another approach would be to generate a PDF file and spit it out by invoking Ghostscript.

Rhys Keepence
Wednesday, September 17, 2003

I'll take a look at the items raised.


Thanks.

Mike Grace
Wednesday, September 17, 2003

Just taken a look at XSL, and FOP and it looks like it might be what I am looking for.

Is there a visual design tools available for XSL-FO or FOP?

Mike Grace
Wednesday, September 17, 2003

A google search reveals that xmlspy claims this capability.  It would be a design tool for XSL-FO, not FOP.

Name withheld out of cowardice
Wednesday, September 17, 2003

I suppose I could always write one myself later I suppose.

Mike Grace
Wednesday, September 17, 2003

Is there any way in XSL-FO to know where I am on the page i.e. all the examples I have seen so far let the text flow straight onto the next page without specifying a continuation message or they print a table that flows onto the next page without repeating the header when it breaks.

I need to be able to make decisions like whether there is space to fit 5 lines of text and if not break etc...

Mike Grace
Thursday, September 18, 2003

*  Recent Topics

*  Fog Creek Home