Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasperreports: can see background image in pdf export but not in docx export

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();     
like image 217
demonz demonz Avatar asked Apr 25 '13 21:04

demonz demonz


People also ask

How do I export a Jasper report?

You can also export reports by right-clicking the report in Jasper Reports, then selecting Export.


1 Answers

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.

like image 64
nahiko Avatar answered Nov 15 '22 14:11

nahiko