 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mario Guest
|
Posted: Mon Sep 12, 2005 6:49 am Post subject: optimizing a printing of a large JPanel ? |
|
|
I tried to find, for a few times, the page or newsgroup to
I discuss hot to optimize a printing of a few page large JPanel which
contains JTree, JTable and 2DGraphics.
I tried everything I found on Net. Some java examples contains enables or
disables antialiasing and other RenderingHints options but I still have the
same 50 MB (in my printer dialog) for a 6 4A pages large JPanel. It is too
much for only 6 page when you must consider that my JPanel can grow on a
much more pages, when I got outofmemory error.
p.s.
if this isn't a right group could you please suggest me the group or web.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Mon Sep 12, 2005 8:52 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Mon, 12 Sep 2005 08:49:47 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
| Quote: | Some java examples contains enables or
disables antialiasing and other RenderingHints options but I still have the
same 50 MB (in my printer dialog) for a 6 4A pages large JPanel. It is too
much for only 6 page when you must consider that my JPanel can grow on a
much more pages, when I got outofmemory error.
Let's do a rough estimate: |
I don't know if you mean A4 pages at 210 × 297 mm or 4A0 pages at 1682
× 2378.
So I will compute for both:
An A4 page is 62370 square mm = 623.70 square cm = 86.67 square
inches.
an 8.5x11 page is 93.5 square inches, slightly bigger.
a 4A0 page is 3,999,796 square mm = 39997.96 square cm = 6,199.7
square inches.
Let's assume your printer has a resolution of 600 dpi.
Let's assume it is using 24 bit colour, three byes per pixel.
for an A4 page you need 31,201,200 pixels per page. 93 MB per page
for an 4A0 page you need 2,231,892,000 pixels per page. 6.6 gb per
page
So the numbers you are getting don't seem out of line. There are
considerably better than these I have just computed. I presume the
format of the printer file is then not a simple raster, but some sort
of drawing code, a miniature postscript.
A friend of mine works at Creo, a company that makes equipment to
render giant postscript posters and magazines in high res with
gigabytes of data sloshing around. It is amazing how quickly
increasing the size or resolution of an image soaks up RAM.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Mon Sep 12, 2005 9:06 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Mon, 12 Sep 2005 08:52:44 GMT, Roedy Green
<look-on (AT) mindprod (DOT) com.invalid> wrote or quoted :
| Quote: | I presume the
format of the printer file is then not a simple raster, but some sort
of drawing code, a miniature postscript.
|
Given that observation, this hints at the sort of things you might to
do shrink the size of that intermediate printer file.
Imagine trying to draw your JPanels by hand in PostScript.
You would want large regions all the same colour. Those bevelled
edges and gradients may be too much for the mindless drawing
intermediate language and may be handled as voluminous bit maps. I am
just guessing.
You might try using the most vanilla l&f you can, and experiment with
the Windows L&F or the native L&F. It has a better chance of being
efficiently handled. I imagine a L&F Like that on the original
Mac/Lisa that just used outlines.
You might find that defining each font only once and using it globally
could make the intermediate file more efficient. Again, I am just
guessing.
If you get very desperate, consider writing a program to take the data
in your panels and generate a PostScript file to represent it. Then
hand that RAW file to your hopefully PostScript aware printer. This
file will be drastically smaller since you can compose PS methods to
draw your various objects from just meager hints.
What you do is shrink the file, but put more of a load on the printer
to compute and render.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Mario Guest
|
Posted: Mon Sep 12, 2005 8:59 pm Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
Roedy Green wrote:
| Quote: | On Mon, 12 Sep 2005 08:52:44 GMT, Roedy Green
[email]look-on (AT) mindprod (DOT) com.inva[/email]lid> wrote or quoted :
I presume the
format of the printer file is then not a simple raster, but some sort
of drawing code, a miniature postscript.
Given that observation, this hints at the sort of things you might to
do shrink the size of that intermediate printer file.
Imagine trying to draw your JPanels by hand in PostScript.
You would want large regions all the same colour. Those bevelled
edges and gradients may be too much for the mindless drawing
intermediate language and may be handled as voluminous bit maps. I am
just guessing.
You might try using the most vanilla l&f you can, and experiment with
the Windows L&F or the native L&F. It has a better chance of being
efficiently handled. I imagine a L&F Like that on the original
Mac/Lisa that just used outlines.
You might find that defining each font only once and using it globally
could make the intermediate file more efficient. Again, I am just
guessing.
If you get very desperate, consider writing a program to take the data
in your panels and generate a PostScript file to represent it. Then
hand that RAW file to your hopefully PostScript aware printer. This
file will be drastically smaller since you can compose PS methods to
draw your various objects from just meager hints.
What you do is shrink the file, but put more of a load on the printer
to compute and render.
|
OK. Don't go away and please be patience with my english and java knowledge.
I try to make an application which is a some sort of "MS Project", but for a
special branch. It is my first serious project which I almost ended when I
notice that it need too much resources (RAM) for some serious usage.
Especially when you know that MS Project needs a few kb for a printing 5-6
pages.
So if you could show me the way more specifically:
- So, I need to generate PostSript file with the standard java packages, I
suppose. How will someone, who don't have a postscript printer, print the
panel ?
- what packages you suggest for a PostScript managing?
- What will be with the performance if I generate PDF file, although, at
this moment, I don't know how can I do it ?
- I also have a preview which use a lot of memory if is large, I suppose.
Could PDF format can also improve performance in that case?
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 1:41 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Mon, 12 Sep 2005 22:59:06 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
| Quote: | suppose. How will someone, who don't have a postscript printer, print the
panel ?
- what packages you suggest for a PostScript managing?
|
You don't need a package. You just write little methods that emit bits
of PS source. The big problem is learning how to write PostScript.
You tackle the problem by using a text editor to write a PS program to
draw a facsimile of your pages. Then write a java program to write out
that program, customising bits of it, but mostly just inserting live
data. PS programmers would say you compose a prologue (a mess of
methods), followed by your data that invoke those methods with your
data as parameters.
PostScript is a postfix language much like Forth, and absolutely
nothing like Java. Some of the primitives are like the tools you use
in paintComponent. As I said earlier, this as desperate measure.
| Quote: | - What will be with the performance if I generate PDF file, although, at
this moment, I don't know how can I do it ?
|
The big thing is your file will be quite small compared with the
intermediate file you have now. PostScript is an intelligent
language, so you can specify what you want tersely and have the
PostScript interpreter in the printer expand it doing whatever
calculations are necessary. You split the work doing some of the
calculations in PS and some in the Java program that spits out the PS
program/data stream.
If you don't have a PostScript printer, you then have to convent the
PS to bit map in some sort of software. See
http://mindprod.com/jgloss/postscript.html Now we are back to where
we started with big bit maps to print. Ouch!
You might send the PS files on a CD to a printing house.
| Quote: | - I also have a preview which use a lot of memory if is large, I suppose.
Could PDF format can also improve performance in that case?
|
That should be easy to test. Just make Java use a PDF printer driver
and see how fat the intermediate files are. I suspect they may be
identical since it is quite possible the work is done in two stages,
Java to Intermediate then intermediate to PDF. See
http://mindprod.com/jgloss/pdf.html
Another experiment make along the same lines its to give Java a FAKE
postscript printer, i.e one that prints to a file, but uses some
popular high end PS printer driver. See what the intermediate file
size and final file size is like. There is a possibility the driver
could use PS instead of the intermediate language, and the file might
be more compact.
You have not yet told me which of the sizes you are really using. 4A0
or A4. Normally giant 4A0 printers would have PS support.
Another approach is to search the web to see if there any tools to
"improve Java printing performance".
You surely are not the first person to run into this problem.
PostScript and PDF are related by not identical. PostScript is what
you send to a printer. PDF is what you post on the web for people to
read. PDF includes navigation, index etc that you don't need to
print.
You may have to hire someone to solve this for you.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 4:47 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Tue, 13 Sep 2005 01:41:57 GMT, Roedy Green
<look-on (AT) mindprod (DOT) com.invalid> wrote or quoted :
| Quote: | Another experiment make along the same lines its to give Java a FAKE
postscript printer, i.e one that prints to a file, but uses some
popular high end PS printer driver. See what the intermediate file
size and final file size is like. There is a possibility the driver
could use PS instead of the intermediate language, and the file might
be more compact.
|
Here's yet another experiment.
Go into Control Panel | Printers | Properties | Advanced | Print
Processor and try out various options to see if any give you smaller
intermediate files.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 6:18 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Mon, 12 Sep 2005 08:49:47 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
| Quote: | I tried everything I found on Net. Some java examples contains enables or
disables antialiasing and other RenderingHints options but I still have the
same 50 MB (in my printer dialog) for a 6 4A pages large JPanel.
|
Here yet another approach . It was the main approach back in the days
of DOS.
What you did was write a file of printer commands and data specific to
your brand and model of printer using an OutputStream of raw bytes.
You used whatever font abilities were built into the printer, no more.
You write methods like bold, italic, etc that emit the correct
commands for your particular printer. Best to set this up as a
pluggable interface you can plug in support for a different printer
later without changing code. This is how Abundance (my own DOS based
language works). I wrote about 75 such printer drivers.
Back then you typically wrote it direct to the parallel port. Today
you would write it to a file and later copy it to the printer port
with a copy command.
Today this approach is harder since printers no longer come with
manuals that tell you their command set.
You did not decorate your output with graphics, just text in various
fonts and sizes.
This is also the approach you often need for specialty printers like
passbook printers, point of sale terminals, or where you need max
speed like printing a million electric bills.
And if I have not given you enough approaches already, try out hitting
PrtSc and see how efficient that is. In theory it should be worse, but
who knows.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Andrey Kuznetsov Guest
|
Posted: Tue Sep 13, 2005 8:31 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
| Quote: | I tried to find, for a few times, the page or newsgroup to
I discuss hot to optimize a printing of a few page large JPanel which
contains JTree, JTable and 2DGraphics.
I tried everything I found on Net. Some java examples contains enables or
disables antialiasing and other RenderingHints options but I still have
the
same 50 MB (in my printer dialog) for a 6 4A pages large JPanel. It is too
much for only 6 page when you must consider that my JPanel can grow on a
much more pages, when I got outofmemory error.
p.s.
if this isn't a right group could you please suggest me the group or web.
|
see
http://java.sun.com/products/java-media/2D/reference/faqs/index.html#spool
--
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
|
|
| Back to top |
|
 |
Mario Guest
|
Posted: Tue Sep 13, 2005 9:28 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
Roedy Green wrote:
| Quote: | On Mon, 12 Sep 2005 22:59:06 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
suppose. How will someone, who don't have a postscript printer, print the
panel ?
- what packages you suggest for a PostScript managing?
You don't need a package. You just write little methods that emit bits
of PS source. The big problem is learning how to write PostScript.
You tackle the problem by using a text editor to write a PS program to
draw a facsimile of your pages. Then write a java program to write out
that program, customising bits of it, but mostly just inserting live
data. PS programmers would say you compose a prologue (a mess of
methods), followed by your data that invoke those methods with your
data as parameters.
PostScript is a postfix language much like Forth, and absolutely
nothing like Java. Some of the primitives are like the tools you use
in paintComponent. As I said earlier, this as desperate measure.
|
- I mean A4 210x297mm, but only for example. My application can print on
every page which is setup on machine.
1. This is example from java.sun.com with which I got PostScript file out.ps
Can I use code below without learning PostScript and got the best
performance?
Example: Print2DtoStream.java
/*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/
import java.io.*;
import java.awt.*;
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
/*
* Use the Java(TM) Print Service API to locate a service which can export
* 2D graphics to a stream as Postscript. This may be spooled to a
* Postscript printer, or used in a postscript viewer.
*/
public class Print2DtoStream implements Printable{
public Print2DtoStream() {
/* Use the pre-defined flavor for a Printable from an InputStream */
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
/* Specify the type of the output stream */
String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
/* Locate factory which can export a GIF image stream as Postscript */
StreamPrintServiceFactory[] factories =
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
flavor, psMimeType);
if (factories.length == 0) {
System.err.println("No suitable factories");
System.exit(0);
}
try {
/* Create a file for the exported postscript */
FileOutputStream fos = new FileOutputStream("out.ps");
/* Create a Stream printer for Postscript */
StreamPrintService sps = factories[0].getPrintService(fos);
/* Create and call a Print Job */
DocPrintJob pj = sps.createPrintJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
Doc doc = new SimpleDoc(this, flavor, null);
pj.print(doc, aset);
fos.close();
} catch (PrintException pe) {
System.err.println(pe);
} catch (IOException ie) {
System.err.println(ie);
}
}
public int print(Graphics g,PageFormat pf,int pageIndex) {
if (pageIndex == 0) {
Graphics2D g2d= (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
g2d.setColor(Color.black);
g2d.drawString("example string", 250, 250);
g2d.fillRect(0, 0, 200, 200);
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
public static void main(String args[]) {
Print2DtoStream sp = new Print2DtoStream();
}
}
2. in a site you got me (http://mindprod.com/jgloss/postscript.html) they
mention a Bravo interface: "Java programs will use the Bravo interface to
generate PostScript programs that are then interpreted for printer, screen
or typesetter.". Where to find it and what will help me if I can make
postscript file like in an example above.
3. I try to wrote an application which is platform independent (at least
that it can be use on Linux and Win) and you said:
| Quote: | Go into Control Panel | Printers | Properties | Advanced | Print
Processor and try out various options to see if any give you smaller
intermediate files.
|
Aren't these processors characteristic of Win platform, or I'm in wrong?
p.s.
my application will suppose to use on a different printers and machines. If
it will be neccessary to learn PostScript to im,prove performance than OK.
But I must be sure that I will not learn something which is across the edge
of java and still didn't satisfied solution.
Did you see Microsoft Project?
It is pretty good and quick application but not specialized. And I and my
application try to find only small place in the world to be able to get out
from boring, don'tWellPaid jobs we have now. :)
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 10:20 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Tue, 13 Sep 2005 11:28:14 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
| Quote: | 1. This is example from java.sun.com with which I got PostScript file out.ps
Can I use code below without learning PostScript and got the best
performance?
|
You are not going to need to know anything about PostScript to use
Sun's code. You just use the Java code the way you would to hook up
any other printer. You will get out a file of text. PS is sort of
human readable. You don't need to read it other than for curiosity.
To print it, you need PS printer.
here is a little PS file I wrote that draws a grid.
%!PS-Adobe-2.0
% copyright 1998 Roedy Green of Canadian Mind Products
% May be freely distributed for any purpose but military.
% GRID - produce alignment grid 1/10" inch horizontally, 1/6"
vertically.
% i.e. 7.2 points horizontally, 12 vertically.
% bold lines every 1", 72 points.
100 dict begin
/pageHeight 11 72 mul def
/pageWidth 8.5 72 mul def
/vertSpacing 72 6 div def
/horSpacing 72 10 div def
/majorGridSpacing 72 def
/HorStripes
{
% vert spacing is passed as a parameter
% draw thin horizontal lines down the entire page
gsave
newpath
0 0 moveto % bottom left
0 % start
exch % inc
pageHeight % stop
{
0
exch moveto % left end of line
pageWidth % line length
0 rlineto % to right end of line
} for
stroke grestore
} def
/ThinHorStripes
{
0 setlinewidth
vertSpacing HorStripes } def
/ThickHorStripes
{
0.5 setlinewidth
majorGridSpacing HorStripes } def
/VertStripes
{
% horizontal spacing is passed as a paramater
% draw thin vertical lines across the entire page.
gsave
newpath
0 0 moveto % bottom left
0 % start
exch % inc
pageWidth % stop
{
0 % bottom margin
moveto % bottom end of line
0
pageHeight % line length
rlineto % top end of line
} for
stroke grestore
} def
/ThinVertStripes
{
0 setlinewidth
horSpacing VertStripes } def
/ThickVertStripes
{
0.5 setlinewidth
majorGridSpacing VertStripes } def
% main
0 setgray % full black
ThinVertStripes
ThinHorStripes
ThickVertStripes
ThickHorStripes
showpage
end
You might do something like this:
copy thefile.ps lpt2:
To copy the file raw to the printer.
You don't need a PS printer to do the experiment. You mainly want to
see if Sun produces a smaller file.
Here in Canada there are all kinds of places where you can take a file
on CD or floppy to get it printed or typeset if it is in PS format.
There might be something similar in Croatia so you could see what sort
of output you might get.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 10:21 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Tue, 13 Sep 2005 11:28:14 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
| Quote: | 2. in a site you got me (http://mindprod.com/jgloss/postscript.html) they
mention a Bravo interface: "Java programs will use the Bravo interface to
generate PostScript programs that are then interpreted for printer, screen
or typesetter.". Where to find it and what will help me if I can make
postscript file like in an example above.
|
I think that just petered out. There is on longer any mention of it
anywhere.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 10:24 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Tue, 13 Sep 2005 11:28:14 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
| Quote: | 3. I try to wrote an application which is platform independent (at least
that it can be use on Linux and Win) and you said:
Go into Control Panel | Printers | Properties | Advanced | Print
Processor and try out various options to see if any give you smaller
intermediate files.
Aren't these processors characteristic of Win platform, or I'm in wrong?
|
Yes this in Windows only. However they are things you might tweak
independent of your code to give you better performance, at least on
Windows. You did not say which platform you were using where you got
the bloat.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 10:25 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Tue, 13 Sep 2005 11:28:14 +0200, Mario <mario_zupan (AT) inet (DOT) hr> wrote
or quoted :
| Quote: | p.s.
my application will suppose to use on a different printers and machines. If
it will be neccessary to learn PostScript to im,prove performance than OK.
But I must be sure that I will not learn something which is across the edge
of java and still didn't satisfied solution.
|
If you go the PS route, then all your customers will need a PS
printer. That may not be a problem for business, but most home users
are going for printers under $100 these days without PS.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Tue Sep 13, 2005 11:11 am Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
On Tue, 13 Sep 2005 06:18:54 GMT, Roedy Green
<look-on (AT) mindprod (DOT) com.invalid> wrote or quoted :
| Quote: | Back then you typically wrote it direct to the parallel port. Today
you would write it to a file and later copy it to the printer port
with a copy command.
|
turns you don't need to do that. javax.print has the ability to send
a raw PS file to a printer.
see http://mindprod.com/jgloss/printing.html#JAVAXPRINT
for sample code.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
|
| Back to top |
|
 |
Mario Guest
|
Posted: Tue Sep 13, 2005 12:51 pm Post subject: Re: optimizing a printing of a large JPanel ? |
|
|
Now, I'm thinking about use code from java example to create PostScript file
and implement option to print PostScript if customer have PS printer.
Thank you very much on your patience.
p.s.
if you know some good site for printing improvement I'll be glad to hear.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|