Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to print components ( printer )  RSS feed

 
Arthur Campos
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello world!
I�m from Brazil and my English can�t be very good... thus, I�m having a problem with Java Printing API.
I�m working on a project (applet) that must have report to print on the paper.
The problem is as follows: I cannot print multiple pages of the contents of a panel. The printer prints only what is in the Graphics object and nothing what is in the panel component.
Then, the question is: how to print contents of the components, as the panel?
I know there is a metod called PrintJob, but it prints one page only.
I�m trying with Printable interface to print multiple pages...
Anyone can help me? It might be a good idea if there is a code example...
I already searched on Google, Altavista, Yahooo... but nothing.
This forum is my last hope that i can solve my problem!!
Thanks in advance!
[ January 20, 2004: Message edited by: Arthur Campos ]
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the documentation for the java.awt.Printable interface:

public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
Prints the page at the specified index into the specified Graphics context in the specified format. A PrinterJob calls the Printable interface to request that a page be rendered into the context specified by graphics. The format of the page to be drawn is specified by pageFormat. The zero based index of the requested page is specified by pageIndex. If the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.

So you need to return PAGE_EXISTS from print() while the pageIndex is less than the number of pages you want to print.
 
Arthur Campos
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! Thanks very much for the reply!!
But the applet must print what is on the panel and not only what is on the Graphics context... it�s that my problem.
For example, if the applet have a panel that contains a Label, a Table and Graphics object, the applet will print Graphics object only!...
 
Arthur Campos
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I obtained a solution for my problem (printing contents in multiple pages).
Here is the code for the peoples that�s having the same problem:

I hope this code can be useful for you.
Good luck!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!