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

Reading and Printing an image from a Database


2004 IR Help

Recommended Posts

By: sherifeldibani - sherifeldibani

Reading and Printing an image from a Database

2005-08-07 20:16

I am very new at this, and this may have been answered many ways berfore.... But never a step by step type instruction....

I have an image stored in a DB field which is read into my report query and available as a field (initially as a string, but I guess I can change it to inputstream, or byte, or whatever....)

How can get that image to print?

The documentations of Jasper did not cover this very well...

Can some please give me a step by step approach? sort of a "For Dummies" approach?

 

 

 

 

By: Lucian Chirita - lucianc

RE: Reading and Printing an image from a Data

2005-08-08 01:05

Hi

 

If you have 1.0.0 and you use JRResultSetDataSource (this is the case when you have the query specified in the report design), you can directly set the type of the field to java.awt.Image and then use the field value as the image expression. The data source will read the field as a binary stream an create the image object that will be rendered.

 

That is, you need something like

 

<field name="PictureField" class="java.awt.Image"/'>

 

and the image element in the detail band:

 

<image>

<reportElement ../>

<graphicElement ../>

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

<![CDATA[$F{PictureField}]]>

</imageExpression>

</image>

 

Regards,

Lucian

 

 

 

 

By: sherifeldibani - sherifeldibani

RE: Reading and Printing an image from a Data

2005-08-08 08:10

Alas, as I am vry green I am using iReport which only support V 0.6.7 for now.... Are there any special tricks to working with 0.6.7?

It seems that V1.0.0 has made things easier....

 

Thank you very much for your answers

 

 

 

 

By: Lucian Chirita - lucianc

RE: Reading and Printing an image from a Data

2005-08-09 00:30

In 0.6.7, you can declare the field as java.io.InputStream and use the field value for the image expression (the expression will have the same type). At fill time, the image element will use the bytes read from the DB as the image data.

 

HTH,

Lucian

 

 

 

 

By: sherifeldibani - sherifeldibani

RE: Reading and Printing an image from a Data

2005-08-09 08:07

Thanks, I will give that a shot!

 

 

 

 

 

By: sherifeldibani - sherifeldibani

RE: Reading and Printing an image from a Data

2005-08-09 16:37

Tried the InputStrem field and expression, but it returned the following error: Not sure why....

 

Error exporting print... java.io.IOException: java.awt.Image fetch aborted or errored at com.lowagie.text.Image.getInstance(Unknown Source) at com.lowagie.text.Image.getInstance(Unknown Source) at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1065) at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:451) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:395) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:262) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:745) at java.lang.Thread.run(Thread.java:534) NESTED BY : java.io.IOException: java.awt.Image fetch aborted or errored at com.lowagie.text.Image.getInstance(Unknown Source) at com.lowagie.text.Image.getInstance(Unknown Source) at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1065) at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:451) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:395) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:262) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:745) at java.lang.Thread.run(Thread.java:534) NESTED BY : net.sf.jasperreports.engine.JRException: Error generating PDF report : Quote1 at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:412) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:262) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:745) at java.lang.Thread.run(Thread.java:534) Caused by: java.io.IOException: java.awt.Image fetch aborted or errored at com.lowagie.text.Image.getInstance(Unknown Source) at com.lowagie.text.Image.getInstance(Unknown Source) at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1065) at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:451) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:395) ... 3 more

 

 

 

 

By: sherifeldibani - sherifeldibani

RE: Reading and Printing an image from a Data

2005-08-09 18:06

Ok The last error is gone now.... Wrong Jasper Version, oops.... Now the report prints but the Image does not show up at all... (It is not empty in the DB)

 

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: Reading and Printing an image from a Data

2005-08-10 02:01

The JRResultSetDataSource uses ResultSet.getBinaryStream() when declaring a java.io.InputStream field. Make sure that your JDBC driver supports this method for your image column type and that the data in the table is indeed image data that can be used by java.awt.Toolkit.createImage(byte[]).

 

Regards,

Lucian

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