Solved

Huge print spool file size.

Posted on 2002-03-28
4
1,001 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
Comment Utility
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
Comment Utility
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
Comment Utility
I did the same.
0
 

Author Comment

by:lenink
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

7 Experts available now in Live!

Get 1:1 Help Now