即使是最简单的Jasperreport jrxml,也是空白PDF [英] Blank PDF even with the simplest Jasperreport jrxml

查看:139
本文介绍了即使是最简单的Jasperreport jrxml,也是空白PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有glassfish 3.1 + JSF的EJB站点,用于jasperreport 4.0.1。该网站在流式传输pdf上没有问题,但是当使用runReportToPdfStream打印PDF时,它产品为空白PDF,下面是代码片段:

i have a EJB site with glassfish 3.1 + JSF for jasperreport 4.0.1. the site has no problem on streaming pdf, but it products blank PDF while printing PDF with runReportToPdfStream, below is the code snippet:

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连接

test.jrxml - a simple report without SQL connection

<?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。请帮忙,如果您需要进一步的分析信息,请告诉我。

no error log in glassfish when generating this report on JSF, but only blank PDF has been shown. Please help, let me know if you need further info for the analysis.

Steven

推荐答案

毕竟, JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream,parameterMap,new JREmptyDataSource()); 解决了这个问题。

After all, JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, new JREmptyDataSource()); solved the problem.

来自Jasperreport的Sanda的报价:

Quote from Sanda of Jasperreport:


默认情况下,没有数据源信息时在报告中,JR不生成任何页面。另一个选项(可以在报告的 whenNoDataType 属性中设置)将打印所有报告部分,但< detail>

By default, when no datasource info is present in a report, JR generates no pages. Another option (which can be set in the report's whenNoDataType attribute) would be to print all report sections, excepting the <detail>.

此报告包含详细信息部分,但仅包含一些静态数据。为了确保此部分也将被打印,最简单的方法是提供一个空数据源,其中包含一个空记录。

This report contains a detail section, but only with some static data. To ensure this section will be printed too, the simplest way is to provide an empty data source, containing a single empty record.

这篇关于即使是最简单的Jasperreport jrxml,也是空白PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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