Jump to content
Changes to the Jaspersoft community edition download ×

Images are not getting displayed in PDF format


dolly_11

Recommended Posts

Hi,

 

Can any one plzzzzzzzzz help me out of this problem?

I'm able to display my company logo on the haeder part of the HTML report but i'm not able to do the same thing in PDF report.I was using IMAGE_URI attribute and setting that parameter to the location where the image is located and so it is working for HTML.But how to do it PDF.Below is the sample code:

//for PDF format report

public static void generateRespondPDFReport(String sourceFile, HashMap parameters,String destFileName,

HttpServletRequest request,HttpServletResponse response) throws Exception

{

JasperPrint jasperPrint = fillReport(sourceFile, parameters); //instantiate an object as ServletOutputStream

ServletOutputStream out1 = response.getOutputStream();

try

{

// create a bytearrayoutputstream object

ByteArrayOutputStream baos =new ByteArrayOutputStream();

//set the content type for the response as pdf

response.setContentType("application/pdf");

//fill the outputstream object baos with jPrint object

JasperExportManager.exportReportToPdfStream(jasperPrint,baos);

//set the content size for the output file (pdf)

response.setContentLength(baos.size());

 

//write the exported outputstream to the servlet outputstream

baos.writeTo(out1);

}

catch (JRException e)

{

 

 

e.printStackTrace();

 

}

//And code for HTML is below

JRHtmlExporter exporter = new JRHtmlExporter();

 

request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);

 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");

 

exporter.exportReport();

 

 

So plz tell me how to make the logo displayed in header part of PDF report as incase of HTML

 

 

thanks in advance

 

regards,

dolly

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

 

Actually i' am able to save and generate the HTML & PDF reports successfully.But when i want to view the reports directly in the browser without saving it i'm able to view both PDF and HTML reports.But the problem is i want to get even the logo to be displayed on the top of the report.But it is getting displayed only in HTML format but not in the PDF format.Why is it so?

My sample code is as below:

 

// for HTML report

JRHtmlExporter exporter = new JRHtmlExporter();

 

request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);

 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");

 

exporter.exportReport();

 

 

And for PDF format is as below:

 

//Code for PDF format

Map imagesMap = new HashMap();

JRPdfExporter exporter = new JRPdfExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");

 

exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,response.getOutputStream());

 

 

exporter.exportReport();

 

 

When i'm using the above code i'm able to view the reports in both HTML and PDF format.But the logo is getting displayed only in HTML report but in PDF report I'm getting a small rectangle sought of image instead of the logo.Why is it so?

Plzz help me out of this problem.......

 

 

Thanks,

dolly

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