Solved

Huge print spool file size.

Posted on 2002-03-28
4
1,020 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
running on tomcat not jboss eap 7.0 3 18
jsp error 6 25
Running JavaFX on the Raspberry Pi 27 39
What browser will run Java? 7 55
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

856 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