Jump to content
We've recently updated our Privacy Statement, available here ×

Large Image Handling - Troubles Base64


Recommended Posts

Hello out there,

we were just happily upgrading from jasperreports 6.12.2 to 6.20.6. Everything went smoothly - only one big thing:

In order to customize their document layout, our users can paste base64-encoded images in their JRXML-file. They do this by defining a variable (string) and pasting the base64-encoded image value in the variable expression. Here is an example with a simple 10x10px image (png).

<variable name="customImage" class="java.lang.String">
<variableExpression><!CDATA["iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAABhJREFUGJVj/DqX4T8DEYCJGEWjCqmnEAAn6QKldRfUigAAAABJRU5ErkJggg=="]]></variableExpression>
</variable>

This variable is then used within an image expression 

javax.imageio.ImageIO.read(new java.io.ByteArrayInputStream(java.util.Base64.getDecoder().decode($V{customImage})))

Unfortunately, we are experiencing serious compile issues with multiple JRXML-files - whenever it comes to more complex images (resulting in huge string values in the variable, background images easily take up to 160k characters). We even had files with compile issues, where the customImage variable had a quite big value - but the variable was never used in an image.

None of the JRXML-files, that are now having compile errors, have been touched ever since - with version 6.12 (or below) we never had issues handling images this way.

We are also having problems with images, where the source is provided to the report via a byte array - as soon as the image source is for example 8000 x 2000px

We are happy to provide more details - is there any known incompatibility with java/tomcat or any other hint for us?

Thank you so much for helping us out!
Regards, Gerd

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Thank you for posting to the Jaspersoft Community. Our team of experts has read your question and we are working to get you an answer as quickly as we can. If you have a Jaspersoft Professional Subscription plan, please visit https://support.tibco.com/s/ for direct access to our technical support teams offering guaranteed response times.
 

Link to comment
Share on other sites

Hello Teodor,

thank you so much for looking into our issue! Of course!

We have prepared an archive with

https://nextcloud.rise-world.com/s/cAdmYqL8wtkceTk

* file a: variable "streamBackground" contains a large string, but is never used in any image (as soon as we remove the variable, the PDF-creation is successful)
* file b: two images are pasted in header and footer (via variable "KOPF" and "img_fuss"; as soon as we replace the variable values with a much shorter string, the PDF-creation is successful)
* file c: large image handling (when provided by byte array from db in parameter logo) with failing image (8268 x 3543px logo), this report works perfectly fine as soon as we compress the logo before storing it in the database

Just to make sure: in Jaspersoft Studio those files all do compile successfully - the problems start by the time we trigger the PDF-creation on our jasper reports server (where we also fill the missing parameters and field-values).

The exceptions we get, don't make sense at all (like ClassCastException), we tried debugging and found, that in those cases the variable and parameter value handling is messed up.

This is our environment

* java 17
* tomcat 9
* we use rhino as js framework in jasper

Hope that helps!
Regards, Gerd

Link to comment
Share on other sites

Hi Team,

thank you for the reminder, and sorry for the delay!

We had already thought that the files alone would be of little help. Unfortunately, the exceptions we get, do not make any sense - as they do not show the root cause. 

In File B for example, during PDF-generation we get a class cast exception, a parameter that is expecting a Boolean value, suddenly gets a String value (that is supposed for a different parameter). It seems, the parameter/variable/field handling gets confused, in case a file contains a large String (like a long Base64 string) - or the image representation as a byte array (2000px and more).

We are working on providing a demo project for you, unfortunately we need a little more time for that. 

Currently, we help ourselves by compressing all images as extensive as possible, so we don't run into this issue for troubled files.

Regards
Gerd

Link to comment
Share on other sites

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...