我有一个带glassfish 3.1 + JSF for jasperreport 4.0.1的EJB站点。该网站在流式pdf上没有问题,但是在使用runReportToPdfStream打印PDF时会生成空白PDF,下面是代码段:
EJB
public class BookEJB {
public void printReport() throws ClassNotFoundException, IOException, JRException {
Map parameterMap = new HashMap();
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
InputStream reportStream = ctx.getExternalContext().getResourceAsStream("/reports/test.jasper");
ServletOutputStream servletOutputStream = response.getOutputStream();
servletOutputStream.flush();
response.setContentType("application/pdf");
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap);
servletOutputStream.flush();
servletOutputStream.close();
ctx.responseComplete();
}}
test.jrxml -没有SQL连接的简单报告
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test" pageWidth="800" pageHeight="1200" columnWidth="555" leftMargin="25" rightMargin="25" topMargin="30" bottomMargin="30">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[]]>
</queryString>
<pageHeader>
<band height="100">
<staticText>
<reportElement x="0" y="0" width="285" height="36"/>
<textElement>
<font size="24" isBold="true"/>
</textElement>
<text><![CDATA[Report of Testing]]></text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="200">
<staticText>
<reportElement x="0" y="0" width="374" height="48"/>
<textElement>
<font size="18"/>
</textElement>
<text><![CDATA[If you don't see this, it didn't work blah blah blah.... ]]></text>
</staticText>
</band>
</detail>
<pageFooter>
<band height="100"/>
</pageFooter>
</jasperReport>
在JSF上生成此报告时,在glassfish中没有错误日志,但是只显示了空白PDF。请帮助,让我知道是否需要进一步的信息进行分析。
史蒂文
最佳答案
毕竟,JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, new JREmptyDataSource());
解决了问题。
来自Jasperreport的Sanda的报价: