xml - PDF导出在Grails 2.3.2中不起作用

标签 xml pdf grails jasper-reports

每当csv和excel导出正常工作但pdf导出不工作时,我正在使用带有iReport 5.5.0的grails 2.3.2和jasperreport 1.8.0,但pdf导出不起作用,我的 Controller 代码为:

def reportWithOutComma = params.summaryReportDataTable.split(",")           
        def inst = Institution.get(session.institutionid.toLong())          
        def result = [:]
        result.data = []
        for(int i = 0;i<reportWithOutComma.size();i+=7){
            def spaceReplacedData = reportWithOutComma.toString().replace('&nbsp;',' ')           
            def name = reportWithOutComma[i].decodeHTML().toString()
            def index1  = name.indexOf("(")
            def stdNames = name.substring(0,index1)           
            result.data << [StudentName:stdNames,
                           TotalDays:reportWithOutComma[i+1].decodeHTML(),
                           Holidays:reportWithOutComma[i+2].decodeHTML(),
                           LeaveDays:reportWithOutComma[i+3].decodeHTML(),
                           AbsentDays:reportWithOutComma[i+4].decodeHTML(),
                           LateMins:reportWithOutComma[i+5].decodeHTML(),
                           EarlyMins:reportWithOutComma[i+6].decodeHTML()]
        }
        params.InstitutionName = inst.name           
        params._format = "PDF"
        params._file = "summaryReport" // filename of xml file           
        def report = jasperService.buildReportDefinition(params, request.getLocale(),result)           
        generateReport(report)           
    }
generateReport包含:
def generateReport = { reportDef ->           
        if (!reportDef.fileFormat.inline && !reportDef.parameters._inline) {           
            response.setHeader("Content-Disposition", "inline; filename=\"${reportDef.parameters._name ?: reportDef.name}.${reportDef.fileFormat.extension}\"");           
            response.setHeader("Content-Type", "${reportDef.fileFormat.mimeTyp}");           
            response.contentType = reportDef.fileFormat.mimeTyp           
            response.characterEncoding = "UTF-8"           
            response.outputStream << reportDef.contentStream.toByteArray()
        } else {}           
    }

我有由iReport创建的xml文件是:
<?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="summaryReport" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2b498a22-3b8e-44c4-a599-d41d0feae942">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="InstitutionName" class="java.lang.String"/>
    <field name="StudentName" class="java.lang.String"/>
    <field name="TotalDays" class="java.lang.String"/>
    <field name="Holidays" class="java.lang.String"/>
    <field name="LeaveDays" class="java.lang.String"/>
    <field name="AbsentDays" class="java.lang.String"/>
    <field name="LateMins" class="java.lang.String"/>
    <field name="EarlyMins" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <pageHeader>
        <band height="108" splitType="Stretch">
            <staticText>
                <reportElement x="34" y="87" width="100" height="20" uuid="0c063040-4acd-4e8f-8982-c87e1dca696a"/>
                <textElement textAlignment="Justified"/>
                <text><![CDATA[StudentName]]></text>
            </staticText>
            <line>
                <reportElement x="34" y="107" width="757" height="1" uuid="2f5845c8-dfa9-43f3-881f-ef34149351c3"/>
            </line>
            <staticText>
                <reportElement x="134" y="87" width="100" height="20" uuid="f999ecfb-3068-4fc4-bd7a-2f5c80dcf303"/>
                <text><![CDATA[TotalDays]]></text>
            </staticText>
            <staticText>
                <reportElement x="234" y="87" width="100" height="20" uuid="955a5328-7b84-4ba2-abae-7de90394bca3"/>
                <text><![CDATA[Holidays]]></text>
            </staticText>
            <textField>
                <reportElement x="671" y="40" width="80" height="20" uuid="d1bf7379-8c77-463c-aa74-c905c2ed9cc8"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="751" y="40" width="40" height="20" uuid="80df4247-690c-49a3-9dbc-85734480b67c"/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="150" y="20" width="404" height="20" uuid="4efbab64-a7d9-4c48-9e9c-ef9d8c5c390d"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression><![CDATA[$P{InstitutionName}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="334" y="87" width="100" height="20" uuid="14b757f8-522c-40f7-8b41-7aad0970c7ee"/>
                <text><![CDATA[LeaveDays]]></text>
            </staticText>
            <staticText>
                <reportElement x="534" y="88" width="100" height="20" uuid="b198e76e-30bb-432f-a083-c17afa5c5482"/>
                <text><![CDATA[LateMins]]></text>
            </staticText>
            <staticText>
                <reportElement x="634" y="87" width="100" height="20" uuid="757bc097-1e2c-4ba2-9aa1-7a15f9177413"/>
                <text><![CDATA[EarlyMins]]></text>
            </staticText>
            <staticText>
                <reportElement x="434" y="87" width="100" height="20" uuid="90a0e43a-9c4f-4475-b101-aef659b726a4"/>
                <text><![CDATA[AbsentDays]]></text>
            </staticText>
        </band>
    </pageHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="134" y="0" width="100" height="20" uuid="8d5ef54f-328e-42fd-ae87-2ef27f71562a"/>
                <textFieldExpression><![CDATA[$F{TotalDays}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="234" y="0" width="100" height="20" uuid="8e5b85b5-8071-48ab-b41c-95b22c5cd8f3"/>
                <textFieldExpression><![CDATA[$F{Holidays}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="34" y="0" width="100" height="20" uuid="691f19c5-9995-45cf-8aa7-bf6d1f953b23"/>
                <textFieldExpression><![CDATA[$F{StudentName}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="334" y="0" width="100" height="20" uuid="d45e1645-93fa-4b00-9d69-a3b079306027"/>
                <textFieldExpression><![CDATA[$F{LeaveDays}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="534" y="0" width="100" height="20" uuid="bf4dd507-7d72-4baf-ac9d-7d5c96a5e51c"/>
                <textFieldExpression><![CDATA[$F{LateMins}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="434" y="0" width="100" height="20" uuid="9a6e330f-f377-427f-969a-29d58a88de3b"/>
                <textFieldExpression><![CDATA[$F{AbsentDays}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="634" y="0" width="100" height="20" uuid="7a5cb204-41c3-4215-9c23-b5ec9310b06e"/>
                <textFieldExpression><![CDATA[$F{EarlyMins}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

并在pdf导出期间显示以下错误:
URI
/sAttend/report/summaryReport
Class
java.lang.NoSuchMethodError
Message
com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V

我该如何解决这个问题,请帮忙。

最佳答案

如果运行grails dependency-report,您可能会在报告中看到itext的2个版本。 Grails用于生成文档的文档可能存在冲突。尝试通过修改BuildConfig以排除Grails所使用的BuildConfig来排除它:

inherits("global") {
    excludes "itext"
}

关于xml - PDF导出在Grails 2.3.2中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23605913/

相关文章:

html - 使用ruby从html文档中删除空格

css - 修改grails中textarea(css)的背景颜色

grails - 超出了GORM/休眠+ GC开销限制

c# - 使用 LINQ 从 XML 中选择多个节点

javascript - Cordova - http 请求不处理本地 php

xml - Odoo:继承网站页脚以将内容包装在 div 中

jquery - 在我的 HTML 页面上显示 PDF Blob 数据

javascript - PDF.js - 一次打印多个文档

c# - PDF 不会自动换行并尊重行位置

grails - 使用Geb维护测试之间的 session