jasperreports:可以在pdf导出中看到背景图像,而在docx导出中看不到 [英] jasperreports: can see background image in pdf export but not in docx export

查看:207
本文介绍了jasperreports:可以在pdf导出中看到背景图像,而在docx导出中看不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

报告生成:

以下代码驻留在servlet中,并在C语言中生成要下载的"letter.docx"字文档和"pika.pdf"文件:

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

我能够看到我在pika中定义的背景图像,但在字母"中看不到.

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

推荐答案

这是另一个与您一样的问题,所有人都说您不能将图像设置为文档报告的背景. 我在旅行中发现的最后一件事是三种选择: JOD报告最激进的选择,如果您可以更改报告引擎,请检查一下. 最后一个教程在本文中,有点儿喜欢将文本用作背景.

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.

这篇关于jasperreports:可以在pdf导出中看到背景图像,而在docx导出中看不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆