
Printing a report
There are four methods for printing a report:
- printReport ( )
- printReport (Object printJob, Object pageFormat, boolean bInteractive, boolean bInBackground, boolean bUseJDK11)
- printReport (Object printJob, Object pageFormat, boolean bInteractive, boolean bInBackground, boolean bUseJDK11, boolean bSeparateLargePage)
- printReport (java.lang.Object job, boolean bInteractive, java.lang.Object pageFormat, boolean bInBackground, JReportPrintListener jreportprintlistener, int useJDK, java.lang.String jobName, java.util.Vector attributeInfo, java.lang.String printer)
And one method for obtaining the status of a report:
The first method printReport() is called to start printing. It will call the last method and use the default parameter values such as: printReport(null, null, true, false, false, false)
The second and third methods allow you to pass the parameters - printJob, pageFormat, bInteractive, bInbackground, bUseJDK11 and bSeparateLargePage. Below is an explanation of each parameter:
- bInteractive
A boolean value. If you set this to false, the print setup dialog will not be shown.
- bInBackground
A boolean value. If you set to true, the printing dialog will not show.
- bUseJDK11
A boolean value. If true, it will use JDK 1.1.x to print the report. Otherwise if you set false, it will use the JDK version that you are running to print the report. The JDK 1.1 printing method is quick in speed but the printing quality is not guaranteed. However, The JDK 1.2 method can return a satisfactory result, even for a gif file, but is slow in speed.
- bSeparateLargePage
A boolean value, if the report page size is larger than the print paper size, and you want to separate a large report page during printing, you should set this property to true. If the print page size is smaller than the report page size, then the report will be printed in multiple pages serially. This means that a large page of the report will be separated automatically. After it is set to true, for JDK 1.2 or higher, the page format dialog will be displayed. In this dialog, you can choose the page format with which to print with. However, for JDK 1.1.x, you must change the printing page format in the print dialog (click the Property button, then choose the page format). Although, it is not recommended to use this printing method, since it may cause some unexpected errors, for example, you may get an extra blank page.
- jreportprintlistener
This is a printing listener. It is an interface that contains two methods: printStart() and printEnd(). You can find it in jet.thinview.print package. This interface is useful for when you want to obtain the print status, for example, start or end. Otherwise, you can set it to null.
- useJDK
An int value. If you set it to 0, it will use JDK 1.1 printing method to print the report. Otherwise if you set it to 1, it will use the JDK 1.2 printing method to print the report. If you set it to 2, it will use the JDK 1.4 printing method to print the report. The JDK 1.1 method is quick in speed but the printing quality is not guaranteed. However, The JDK 1.2 method can return a satisfactory result, even for a gif file, but it is slow in speed. JDK 1.4 method provides added options for printing, such as specifying a paper tray.
- jobName
A String value specifies print job name.
- attributeInfo
A vector whose elements are string. Each String is defined in the interface PrintConfig. For example, you can implement PrintConfig and call its fields as follows: attributeInfo.add(TRAY_MANUAL); attributeInfo.add(ORIENTATION_PORTRAIT);
- printer
Specify the printer to be used. The printer name must include the full path. You can call the getAllPrinters() method for JDK 1.4 to get the list of all system printers. This printReport method is recommend for JDK 1.4 or later version only (many features are only supported by JDK 1.4 or later version). An example of calling this printReport() method:
PrinterJob printJob = PrinterJob.getPrinterJob(); Vector attributeInfo = new Vector();
attributeInfo.add(TRAY_MANUAL); attributeInfo.add(ORIENTATION_PORTRAIT);
bean.printReport(printJob, true, printJob.defaultPage(), false, null,2,"JReport",
attributeInfo,"\\\\127.0.0.1\\Samsung SCX-5x12 Series PCL 6");
|
Example1
Under JDK 1.2 or later version, if you use the JDK 1.2 printing method (boolean bUseJDK11), you can call the printReport method as follows:
PrinterJob printJob = PrinterJob.getPrinterJob();
bean.printReport(printJob, printJob.defaultPage(), false, false, false);
Or, if you do not want to get PrinterJob, simply call:
bean.printReport (null, null, false, false, false);
Example2
Under JDK 1.2 or higher, if you use JDK 1.1 printing method, you are best recommended not to get PrintJob, just call:
bean.printReport (null, null, false, false, true);
After the print process has started, the method getPrintStatus ( ) can be used to obtain the print job status. The returned values of getPrintStatus ( ) are:
- "No Print Job"
- "Busy"
- "OK"
- Other error message (if there is an error).
