• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Writing formatted output to printer?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I print a form, where I want to control the position and appearance of text anywhere on a printed page? For example, say I have a Java program that prints nicely formatted invoices, or perhaps bank statements, where I want to use different fonts and place everything just right.
Is anything built into the standard Java API that will help? How about 3rd party packages? Can I somehow use AWT to create the image and then direct it to the printer? I could even write the data out as xml and then use xsl to format it, although that sure seems like the long way around.
I figure there must be a simple way, because doing this is fundamental to a lot of business applications. It's just not obvious to me what the best way is.
Ron
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a little much to go into a lot of detail here but there is a PrinterJob class and a Printable interface that allow you to do what you want. You use methods of the Graphics class to print to the printer just as you would use these methods to draw on the screen. Core Java Volume 2 by Horstmann has some good examples in Chapter 7, Advanced AWT.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!