11

Report generation:

The following code resides in a servlet and generates both a "letter.docx" word document to download and a "pika.pdf" file in C:

I am able to see the background image i defined in pika, but not in "letter".

        InputStream is = request.getServletContext().getResourceAsStream("/resources/reports/" +name);      
        JasperReport jr = JasperCompileManager.compileReport(is);                           
        JasperPrint jp = JasperFillManager.fillReport(jr, params, ds);      
        JRExporter exp = new JRDocxExporter();
        exp.setParameter(JRExporterParameter.JASPER_PRINT, jp);         
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        exp.setParameter(JRExporterParameter.OUTPUT_STREAM, bos);       
        exp.exportReport(); 

        JasperExportManager.exportReportToPdfFile(jp, "C:\\pika.pdf");

        byte[] bytes = bos.toByteArray();       

        response.reset();       
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment; filename=\"letter.docx\"");              
        response.getOutputStream().write(bytes);
        response.getOutputStream().flush();
        response.getOutputStream().close();     
2
  • what format is your image?? have you tried changing the format? Jan 6, 2018 at 5:03
  • @RuslanLópezCarro png image Jan 9, 2018 at 17:14

3 Answers 3

2

Looking for an answer in the jasper community, i can see you are not the first one that asked by this. Here is another question like yours all says that you can't set an image as background in doc reports. The last things i found in my travel are three alternatives: JOD Reports The most radical option, if you can change you report engine, check this out. Other tutorial that shows how to embed images, but i'm not sure that works in Word docs specific case. The last tutorial Here in SO, a little taste to put text as background.

Hope this helps, cheers.

1

I don't have enough information on your case but once I had a very nasty problem with Excel export, a cell wasn't being shown in XLS but in PDF it was shown fine. What I found out was just a single pixel misalignment between the header band and value band for the same column. This brought an extra cell into each of the values rows and JR couldn't populate it correctly. So checking for misalignments in the JRXML is my advice, based upon previous experiences. Since MS Office formats are not well standardized as PDF or HTML, their exporting tends to be more "glitched".

1

JRDocxExporter is a grid exporter, it generates a table and then populates each cell of this table with the elements in the jasper template. If an element in the template overlaps another element, the further element does not display, because in a table a cell cannot overlap another cell.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.