Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print report with a self-made report format in Java?

Status
Not open for further replies.

huiyanx2

Technical User
Nov 1, 2002
11
HK
Hello, I would like to know how can I make reports in Java? I have heard that external library is needed, however, do you know which one do I need?

Thanks very much!!
 
Hi !

Perhap's it's existing libraries that can do that. You can do this with the standard API, too, but it's a lot of work :

You have to build a picture with the java.awt package, in the method "print" of a class that extends "java.awt.print.Printable".

Then here is the code for printing:

Code:
    Book book = new Book();
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PageFormat pageFormat = printJob.defaultPage();
    pageFormat.setOrientation(PageFormat.PORTRAIT);

    Paper paper = new Paper();
    Rectangle area = /*your area*/;
    paper.setImageableArea(area.x, area.y, area.width, area.height);
    pageFormat.setPaper(paper);
    pageFormat = printJob.validatePage(pageFormat);

    book.append(page, pageFormat, page.getNbPages());
    printJob.setPageable(book);

    try {
      // - print
      printJob.print();
    } catch (PrinterException x) {
      x.printStackTrace();
    }

In your implementation of the method print, you receive a parameter that specify you the index of the page to print.

Thomas A free GUI for your database:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top