I am using grails 2.3.2 and jasperreport 1.8.0 with iReport 5.5.0 everytime csv and excel export are working but pdf export is not working,I have controller code as:

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)           
    }

where generateReport contains:

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 {}           
    }

and i have xml file as created by iReport is:

<?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>

and during pdf export it shows following error:

URI
/sAttend/report/summaryReport
Class
java.lang.NoSuchMethodError
Message
com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending(Z)V

how can i solve this problem please help.

有帮助吗?

解决方案 2

I tried both but it did not work so i added
build "com.lowagie:itext:2.1.7" in BuildConfig.groovy including

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

and updated iText 2.0.8 to 2.1.7

其他提示

If you run grails dependency-report you will probably see that there are 2 versions of itext in the report. The one that Grails uses to generate documentation is probably conflicting. Try and exclude it by modifying your BuildConfig to exlclude the one used by Grails:

inherits("global") {
    excludes "itext"
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top