Jump to content

Problem with HTML Images


2005 IR Help

Recommended Posts

By: Nishant Miglani - nishantm

Problem with HTML Images

2004-03-10 07:18

Hello,

 

I was having an HTML Image problem earlier, and looked into it a bit deeper.

 

When I try to output an image to an HTML file, it works perfectly. When I try to output the same image to an HTML stream, it doesn't work.

 

What happens is that the HTML file is created in both cases. In the file code, the image file path (in the browser) is recognized as 'file:///C:/testreport.html_files/img_1'. But in the stream code, its 'file:///C:/nullimg_1' instead.

 

I have included all the code below to refer to.

 

I'm not sure why this is happening. Any help will be appreciated.

 

Thanks

 

----

 

 

Here is the code that works:

 

JasperDesign jasperDesign;

JasperReport jasperReport;

 

jasperDesign = JasperManager.loadXmlDesign("C:\image.xml");

 

jasperReport = JasperCompileManager.compileReport(jasperDesign);

 

JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, null, new JREmptyDataSource());

 

JRHtmlExporter exporter = new JRHtmlExporter();

 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:\testreport.html");

 

exporter.exportReport();

 

System.out.println("Done!");

fos.close();

 

 

Here is the code that doesn't work:

 

File file = new File("C:\testreport.html");

file.createNewFile();

FileOutputStream fos = new FileOutputStream(file);

 

JasperDesign jasperDesign;

JasperReport jasperReport;

 

jasperDesign = JasperManager.loadXmlDesign("C:\image.xml");

 

jasperReport = JasperCompileManager.compileReport(jasperDesign);

 

JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, null, new JREmptyDataSource());

 

JRHtmlExporter exporter = new JRHtmlExporter();

 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);

 

exporter.exportReport();

 

System.out.println("Done!");

fos.close();

 

 

Here is the XML file for reference:

 

<?xml version="1.0" encoding="UTF-8" ?>

 

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"

"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="ImagesReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" columnCount="1" printOrder="Vertical" orientation="Portrait" whenNoDataType="NoPages" columnSpacing="0" isTitleNewPage="false" isSummaryNewPage="false">

<title>

<band height="782" isSplitAllowed="true">

<image scaleImage="RetainShape" hAlign="Left" vAlign="Top" isUsingCache="true" evaluationTime="Now" hyperlinkType="None">

<reportElement x="0" y="50" width="150" height="40" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<graphicElement pen="Thin" fill="Solid" />

<imageExpression class="java.lang.String">

<![CDATA[ "C:\bugsbunny.jpg"

]]>

</imageExpression>

</image>

<staticText>

<reportElement x="160" y="50" width="390" height="40" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" />

<textElement textAlignment="Left" verticalAlignment="Top" lineSpacing="Single" />

<text>

<![CDATA[ Here's the image!

]]>

</text>

</staticText>

</band>

</title>

</jasperReport>

 

 

 

 

 

By: Nishant Miglani - nishantm

RE: Problem with HTML Images

2004-03-12 12:23

Do any of you have any idea?? Teodor??

 

I really need to resolve this in my project before I can move on!

 

Thanks

 

 

 

 

 

By: Gregory A. Swarthout - gswarthout

RE: Problem with HTML Images

2004-03-12 12:45

This can be a bit tricky. You need to set a URI to use to reference the images.

 

Specifically, add these lines before exporter,exportReport():

 

Map imagesMap = new HashMap();

htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap); htmlExporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, myURI);

 

An example of myURI is "report?image="

 

Then place the resulting imageMap into the session like:

 

request.getSession().setAttribute("IMAGES_MAP", imagesMap);

 

 

 

 

 

By: Gregory A. Swarthout - gswarthout

RE: Problem with HTML Images

2004-03-12 12:55

There really is a bit more to it than that, because you then need a servlet or jsp that knows what to to with the imageMap and will feed back images from the given URI. Take a look at the webapp sample, specifically the html.jsp and image.jsp files.

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