views:

109

answers:

3

I'm looking for a good tool for printing Invoices, Receipts and similar documents in Java Swing. I have tried JasperReports but it is pretty hard to get a dynamic layout and it is designing for reports.

A requirement that I have is that the document should be sent directly to the printer and must not be saved to a file. So some tools that first creates an Office Document or a PDF document isn't a solution for me.

Any recommendations?

A: 

Printing in Java revolves around a fairly simple but powerful API that provides you with a canvas. Fromthere you can easily paint any information using the Java2D API in the same way you would override a paintComponent() function.

Timo
But that is very low-level and time-consuming. You have to measure the length or every word with `FontMetrics` and so on... That's why I'm looking for a tool for this.
Jonas
This seem sadly to be the solution for this problem in the Java world :(
Jonas
+1  A: 

You might want to give Docmosis a go. You can create dynamic documents in various formats with the advantage that layout is specified in a template (being a simple doc or odt file) and content can be dynamically managed based on data. The type of layout your link refers to is pretty easy to achieve by using Docmosis conditional fields or by adjusting your input data.

In terms of printing only, Docmosis lets you stream the resulting output document anywhere. You could stream it to code that will send it to a printer directly.

jowierun
Docmosis looks good, but I would like a tool with a more open license.
Jonas
What is the license limitation that is a problem? You can freely distribute the community edition.
jowierun
+1  A: 

I recommend to use DynamicReports, an open source and based on JasperReports. You can send report directly to the printer.

Ricardo
+1: the fluent API looks great, easy to use and still powerfull
Matthieu BROUILLARD
It seem to have the same weaknesses as JasperReports? It's pretty hard to do other documents than reports.
Jonas