0 byte image not printing

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Michael Jacobs

0 byte image not printing

Post by Michael Jacobs » Wed Dec 04, 2002 10:12 pm

Hi,

I use the ChartUtilities.writeChartAsJPEG() method to send an image to the screen through the output stream. The page displays fine in IE, but when I print the page the image is not printed, and when I right click on the image and look at it's properties, it says: "Size: 0 bytes". The image prints fine in Netscape.

Has anyone seen this behavior before? Do I need to save the image to disk outside of the WEB-INF to get the image to print correctly (saving it outside the WEB-INF would allow me to link to it directly)?

My code is simple:

ServletOutputStream out = response.getOutputStream();
response.setContentType("image/jpeg");
ChartUtilities.writeChartAsJPEG(out, cp.getChart(), cp.getWidth(), cp.getHeight());
out.close();

(the cp object is a ChartProxy class that wraps the JFreeChart and the ChartRenderingInfo objects)

Michael Jacobs

David Gilbert

Re: 0 byte image not printing

Post by David Gilbert » Thu Dec 05, 2002 12:09 am

Hi Michael,

This problem has been reported before (a while back), but I'm not aware of a solution sorry.

Regards,

DG

Michael Jacobs

Re: 0 byte image not printing

Post by Michael Jacobs » Thu Dec 05, 2002 5:05 am

David,

If it is a problem with the jfreechart package, then I can try to debug it. I wasn't sure if it was a more general IE problem, or a web server problem, or a jfreechart problem.

Did the prior bug report do any research about the issue?

Michael

Richard Atkinson

Re: 0 byte image not printing

Post by Richard Atkinson » Thu Dec 05, 2002 9:28 am

Trying checking to see if the image can be retrieved twice from the server without re-requesting the page. The browser may well be trying to re-request the image when printing it. Failure to get an image back would cause the problems you are seeing. To test it:

Request the page normally
View the page source
Take the src attribute from the img tag of your graph and paste that into your browsers Address bar

I had similar problems a few months ago when I was just creating the chart in memory, streaming it to the browser and then destroying the chart object. The problem is that you cannot predict when the browser will re-request an image. To get around the problem I developed the com.jrefinery.chart.servlet package to persist charts to the temporary directory and provide a servlet to stream saved charts to the user that created them. When the user's session expires all the charts that they have created in the temporary directory are deleted. It was the neatest way I could find around the problem.

Hope this helps,
Regards,
Richard...

Michael Jacobs

Re: 0 byte image not printing

Post by Michael Jacobs » Fri Dec 06, 2002 1:35 am

Yes, I have already resigned myself to saving the images to disk. I'll make this change and I'm sure it will work correctly.

Locked