Hi,
When I print a page of text, the print queue box will
show 1.93MB of 2.06MB. It takes long time to print
a page of text. The same file when printed from other
application(Textpad) takes 26k and prints faster. Iam
currently preparing reports for our application, which we
develop using java. Printing multiple pages is a must and
doing so takes forever to print a 10 page report. All I
need is to reduce the spool file size to somewhat
nearer to what other applications like Notepad/Textpad do.
The same problem was raised as a BUG and closed.
The application we develop is using IBM JDK1.2.
I know this problem is fixed in IBM JDK1.3.
But I searching for a fix in JDK1.2 itself, since
porting to IBM JDK1.3 is not in our plans now.
URL :
http://developer.java.sun.com/developer/bugParade/bugs/4186108.html
BUg Info:
**********
Bug Id 4186108
Votes 292
Synopsis Printing more than 1 page using
PrinterJob.print(): long time, huge
files.
Category java:classes_2D
ReportedAgainst 1.2RC1, 1.2RC2, 1.2fcs
Release Fixed
State Closed, duplicate of 4227245
Related Bugs 4185668
Submit Date Oct 30, 1998
Description
***********
RFE 4227245 is changing the way text is printed in
the majority of cases so as to make vast reuction in
spool file sizes, particularly for PCL and PS printers.
That RFE is partially implemented in Kestrel (Java 2
V1.3) Beta for "physical" fonts obtained via getAllFonts
() or getAvailableFontFanilyName
s().The improvement for
logical fonts such as "dialog" is expected to be
implemented by Kestrel's FCS.
Here is my Sample Code
-----------------------
/* source for Printable implementation */
import java.awt.print.*;
import java.awt.*;
import java.util.*;
public class PrintTest implements Printable{
public int print(Graphics g, PageFormat format, int
pageIndex){
int totalWidth = (int) format.getImageableWidth()
;
int totalHeight = (int) format.getImageableHeight(
);
int posX = (int) (format.getImageableX());
int posY = (int) (format.getImageableY());
posY += 10;
FontMetrics fontMetrics =
g.getFontMetrics(new Font("Courier", Font.PLAIN, 7));
int charWidth = fontMetrics.stringWidth("W
");
int charHeight = fontMetrics.getHeight() + 1;
int noOfLines = Math.round(totalHeight / charHeight);
int noOfCharsPerLine = Math.round(totalWidth /
charWidth);
String printContent =
"Test print message just to check the size of the
spool file size.";
g.setFont(new Font("Courier", Font.PLAIN, 7));
if (pageIndex > 0) {
for(int i=0;i< noOfLines;i++){
g.drawString(printContent,
posX, posY);
posY += charHeight;
}
}
return Printable.PAGE_EXISTS;
}
public static void main(String args[]){
PrintTest printTest = new PrintTest();
PrinterJob job = PrinterJob.getPrinterJob()
;
PageFormat landscape = job.defaultPage();
landscape.setOrientation(P
ageFormat.
LANDSCAPE)
;
Book bk = new Book();
bk.append(printTest, landscape, 1);
job.setPageable(bk);
if (job.printDialog()) {
try {
job.print();
}
catch (Exception exc) {
System.out.println("Could not print the document.");
}
}
}
}
Thank you,
Lenin.
/*
Note: Printing was done on HP LaserJet 2100.
OS: Windows 2000 Professional Edition
*/