Jump to content
Changes to the Jaspersoft community edition download ×

Issue when image falls near page break

2005 IR Help

Recommended Posts

By: Frank Jacobs - forkjake

Issue when image falls near page break

2004-09-28 08:39

I'm having an issue when an image falls near a page break. In that event, the image does not display and the rest of the report following the image is blank.


I also get this error message in a stack trace:


java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0


There are two workarounds that I've found for this:


1. Scale my images so that the chance of them hitting a page break doesn't happen. However, this workaround isn't always viable since some of my reports have a lot of dynamically-generated images (e.g. JFreeChart graphs).


2. Use the read() method of ImageIO to wrap the input stream:


<imageExpression class="java.awt.Image">




This fixes the problem, but has the negative aspect of increasing my PDF file size. This is because my input stream contains my image compressed with PNG. However, the read method of ImageIO returns a java.awt.image.BufferedImage (which is an uncompressed representation of the image). Thus, the end result is a much larger PDF since all of the images get uncompressed before being placed in the PDF.



Does anyone have any comments or hints regarding this issue?


Thanks. :-)








By: Frank Jacobs - forkjake

RE: Issue when image falls near page break

2004-10-07 12:52

I resoved this issue. It has to do with the InputStream getting read more than once. It seems that when an image is near a page break, JasperReports will read the image to determine its size. From this, it will decide whether there is enough room to display the image. If not, it will display it on the next page. However, it seems to attempt to read the InputStream again in this case. Since the stream has already been read once, it returns no bytes.


To get around this problem, I created a workaround. The workaround is to make a subclass of InputStream that automatically rewinds itself when necessary. This allows the stream to be re-read as many times as necessary.







By: rpgmr - rpgmr

RE: Issue when image falls near page break

2004-10-07 19:04

Cool, it's not easy to figure out a workaround for a _feature like this.





By: odc - sameena

RE: Issue when image falls near page break

2004-10-20 21:39

how to convert a jpeg image to a java.awt.image using scriptlet?

may i know what method r u following to include images in jasper reports?


thks in advance

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...