Skip to main content

Printing

4 replies [Last post]
soupdragon
Offline
Joined: 2006-01-07

Lately I've been using the print API for the first time and I really think it must be possible to come up with some improvements.

I think fairly typical printing would involve a mixture of fixed size items, and tables which may run over serveral pages. The PrintPage Book functionality seems aimed at this kind of thing, but the TablePrinter doesn't cooperate. Doesn't give you the number of pages, doesn't allow you to treat the first and last pages (where a table is likely to compete with other stuff) differently. And, if print is going to rotate arround printables, should there be a getPrintable on the generic awt components?

I'm not clear exactly what's wanted but, it seems to me, there's a need for some equivalent to the LayoutManger system and some kind of conditional page break system as you'd find in Word processing. I've got layed out boxes printing, but it's been an uphill struggle and I've wasted about half a ream of printer paper.

And that's another issue. How about a built-in print preview function?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jancarel
Offline
Joined: 2004-03-11

You're right, best way is IMO to avoid the inbuilt printing possibilities.
After some frustrating trials, I purchased J2PrinterWorks, a very reasonably priced commercial package I can recommend.
Prints all swing components (and combinations of).
Check out the required features on www.wildcrest.com.
Trial version available.

soupdragon
Offline
Joined: 2006-01-07

Oh, our management are far too parsimonious to fork out for something when I can code arround it's absence ;-)

I've been giving the matter further thought and it seems to me that we need, basically, two elements. A template, consisting of fixed elements (headers, footers etc.) and sequences which consist of a sequence of templates. Each of the two can contain the other. Each element has a minimum and preferred size.

We could also do with a previewer in the form of a PrintService.

Sounds like about 2-3 days work (and another half-ream of printer paper).

jancarel
Offline
Joined: 2004-03-11

>>Sounds like about 2-3 days work

Well, good luck. Let us know about your progress.

soupdragon
Offline
Joined: 2006-01-07

Finally got round to sorting it out, it was more work than I'd anticipated. But because I did it at work I doubt I'll get permission to share it. Seem to be some pretty weird clipping going on with the print contexts.

As I anticipated there are three core classes; PrintLayout which arranges elements on a page, PrintSequence which prints a series of items in a window on each of serveral pages and a PrintTable for JTables. Also some smaller wrappers for awt Components and Containers and a PrintSideBySide class for columns.

I wound up laying out the whole document the first time print is called. Partial layout was just too messy (and generally rather pointless). Initially I started out just doing layout as far as the highest page number requested but I abandoned it as a dead end.