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

jasper-reports, java, ms-word, pdf

Solution

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.

Problem

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(); ```

Original source