I use jasper plugin to get report in pdf .I am trying to get report using this example(http://grails.org/plugin/jasper).To get particular id information in pdf format used below codes.
<div class="buttons">
<g:form>
<g:hiddenField name="id" value="${userManagementInstance?.id}" />
<span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
<span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
</g:form>
</div>
<g:jasperReport jasper="use" format="PDF" name="users">
<input type="hidden" name="id" value="${userManagementInstance?.id}" />
</g:jasperReport>
I used above code in show.gsp page to get particular id report.
<?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="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<style name="pagetitle" isDefault="false" fontName="SansSerif" fontSize="14"/>
<parameter name="id" isForPrompting="false" class="java.lang.String">
<defaultValueExpression><![CDATA["<parameter error>"]]></defaultValueExpression>
</parameter>
<queryString><![CDATA[select * from user_management where id =$P{id}]]></queryString>
<field name="id" class="java.lang.String"/>
<field name="user_id" class="java.lang.String"/>
<field name="user_name" class="java.lang.String"/>
<background>
<band/>
</background>
<title>
<band height="79">
<staticText>
<reportElement style="pagetitle" x="0" y="0" width="201" height="46"/>
<textElement/>
<text><![CDATA[all]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35"/>
</pageHeader>
<columnHeader>
<band height="61">
<staticText>
<reportElement key="staticText" x="0" y="39" width="100" height="20"/>
<textElement/>
<text><![CDATA[id]]></text>
</staticText>
<staticText>
<reportElement key="staticText" x="130" y="39" width="100" height="20"/>
<textElement/>
<text><![CDATA[userId]]></text>
</staticText>
<staticText>
<reportElement key="staticText" x="266" y="39" width="100" height="20"/>
<textElement/>
<text><![CDATA[userName]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="42">
<textField isBlankWhenNull="false" hyperlinkType="None">
<reportElement key="textField" x="0" y="15" width="130" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false" hyperlinkType="None">
<reportElement key="textField" x="130" y="15" width="136" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{user_id}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false" hyperlinkType="None">
<reportElement key="textField" x="266" y="15" width="130" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{user_name}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45"/>
</columnFooter>
<pageFooter>
<band height="54"/>
</pageFooter>
<summary>
<band height="42"/>
</summary>
</jasperReport>
I use above code in web-apps/report folder use.jasper.
Error 500: Executing action [index] of controller [org.codehaus.groovy.grails.plugins.jasper.JasperController] in plugin [jasper] caused exception: null
Servlet: grails
URI: /inventoryManagment/grails/jasper.dispatch
Exception Message: invalid stream header: 3C3F786D
Caused by: invalid stream header: 3C3F786D
Class: Unknown
At Line: [-1]
But i am getting error that is invalid stream header: 3C3F786D. So please guide me to solve this problem.
It looks like you are refering to the subreport using the .jrxml file. But, you should be using the compiled version .jasper.
I hope that works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With