Solved

Huge print spool file size.

Posted on 2002-03-28
4
1,006 Views
Last Modified: 2012-06-21
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 my
worries are reducing the spool file size to somewhat
nearer to what other applications like Notepad/Textpad
make.

The same problem was raised as a BUG and closed. I don't
know where the fix is.
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 getAvailableFontFanilyNames().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(PageFormat.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.");
   }
  }
 }

}

  Iam sure some one would have got a solution for this.
Thank you,
Lenin.

/*
Note: Printing was done on HP LaserJet 2100.
Java(TM) Plug-in: Version 1.3.1_02
Using JRE version 1.3.1_02 Java HotSpot(TM) Client VM
OS: Windows 2000 Professional Edition
*/

0
Comment
Question by:lenink
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6902935
Hi lenink,
In this page (BUG report) the explanation is that this bug is fixed in the later varions of java and thus - it is closed.
I ran you example with java 1.3.1 under Windows and the spool file size was 27K. May you have to this version or hier.
0
 

Author Comment

by:lenink
ID: 6904771
Hi Venci75,
    Iam afraid, I have tested the example in JDK1.3, jdk 1.3.1_02 and j2sdk1.4. I could not find any difference. The spool file size was still 2.08MB. I tried printing a page using the Notepad application, which came along with J2sdk1.4. That make less spool file size (16kb).
    Whenever I run the sample code, I will get the print dialog. On clicking ok, a printer icon will appear in the system tray. I double click on that, and check for the size column. This is the way I check for the spool file size. How do you check your spool file size? Please correct me if Iam wrong.

Thank You,
Lenin.
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 300 total points
ID: 6904773
I did the same.
0
 

Author Comment

by:lenink
ID: 6920172
Hi Venci75,
 I found out the problem, the spool file size is less than 20k. The problem was I had IBM JDK1.2 installed on my machine. When I removed that from my Path, it worked fine.
Iam happy to give you the points now.
Thanks,
Lenin.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 44
Groovy:unable to resolve class error 2 66
simple java question 3 44
jar file executable 12 38
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now