Jump to content

resolving image as a file in PDF Exporter


andrewsc

Recommended Posts

Hi,

we have a report which can be exported just fine to HTML, but fails when exporting to PDF. The problem is that the image is being loaded from a URL, but we designed the report to load images from the file system. The flow is something like this:

   - fillReportToFile
   - reload the file into a JasperPrint object
   - JRHtmlExporter..exportReport();  // this works fine
   - reload the same file again into a JasperPrint object
   - JRPdfExporter.exportReport(); // this fails
  
The stacktrace is:

net.sf.jasperreports.engine.JRException: Error loading byte data :
https://my.host.com:9090/MyAppName/images_directory/my_image.jsp
 at net.sf.jasperreports.engine.util.JRLoader.loadBytes(JRLoader.java:350)
 at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:467)
 at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:428)
 at net.sf.jasperreports.engine.JRImageRenderer.getImageData(JRImageRenderer.java:402)
 at net.sf.jasperreports.engine.JRImageRenderer.getOnErrorRendererForImageData(JRImageRenderer.java:290)
 at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1058)
 at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:675)
 at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:641)
 at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:536)
 at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:323)  
 
I could reproduce this with Eclipse debugger. In the JRPdfExporter.exportImage method, I could see the "renderer" attached to the JRPrintImage argument already had an imageLocation formatted as a URL.

I wonder how could we avoid this. We would like the "imageLocation" to resolve to the file system. This application runs under WebSphere, and the file system will resolve relative to the application root. This seems to be happening elsewhere in the application.

Is there any parameter in the PDF exporter, to force images to resolve from file system ?
I cannot find it in the book. The report design already uses an IMAGES_DIR parameter as string, but that is not an exportter parameter.

Regards,

Andrew

P.S. in this case,  the failure is caled by an invalid httpS ceritficate, but this is not the point.   The stacktrace continues:

Caused by: javax.net.ssl.SSLHandshakeException: com.ibm.jsse2.util.h:

        No trusted certificate found
       
 at com.ibm.jsse2.n.a(n.java:37)
 at com.ibm.jsse2.jc.a(jc.java:388)
 at com.ibm.jsse2.db.a(db.java:390)
 at com.ibm.jsse2.db.a(db.java:161)
 at com.ibm.jsse2.eb.a(eb.java:20)
 at com.ibm.jsse2.eb.a(eb.java:152)
 at com.ibm.jsse2.db.m(db.java:303)
 at com.ibm.jsse2.db.a(db.java:230)
 at com.ibm.jsse2.jc.a(jc.java:446)
 at com.ibm.jsse2.jc.g(jc.java:433)
 at com.ibm.jsse2.jc.a(jc.java:335)
 at com.ibm.jsse2.jc.startHandshake(jc.java:523)
 at com.ibm.net.ssl.www2.protocol.https.b.afterConnect(b.java:122)
 at com.ibm.net.ssl.www2.protocol.https.c.connect(c.java:43)
 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:943)
 at com.ibm.net.ssl.www2.protocol.https.a.getInputStream(a.java:66)
 at java.net.URL.openStream(URL.java:1042)
 at net.sf.jasperreports.engine.util.JRLoader.loadBytes(JRLoader.java:336)

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi,

 

Please attach the JRXML or copy/paste the image element declaration. Is the image using the isLazy flag?

 

Note that since you have put a HTTPS URL as the source of your image, how would the PDF exporter know it has to use some local file instead of this URL? I'm not sure how would you expect this to work.

I mean, if you tell the program to load the image from a public HTTPS location, how would you expect the program to ignore what you told it and actually load the image from somewhere else?

 

I suspect that for HTML it works because the image has isLazy="true" and because the HTML report is displayed by the same Web server application from which the image has to be taken from. In case it is so, you are benefiting from a browser feature that is not available when we export to PDF. Our PDF exporter will actually try to connect to the URL you gave and load the image from there. And the server does not let it because of the security issue involved. You need certificates and stuff like that, just like any other client application trying to connect to your server through HTTPS.

 

I hope this helps,
Teodor

 

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