2005 IR Help Posted August 26, 2006 Share Posted August 26, 2006 By: Gopalakrishnan - gopkrish3 Problem while exporting report to HTML format 2004-07-14 01:55 Hai I am new to jasper report. I tried creating a report using XML as the datasource. The report contains two columns name job. I used JRXMLDataSource to load the xml and i exported report to HTML and PDF format. Both the files are created successfully, but only job column is displayed in the HTML file and both the columns are displayed in the PDF file. I don't know how it missed out the name column. i tried to figure out but i can't able to. Please help me to resolve this. Java file ========= import dori.jasper.engine.export.JRPdfExporter; import dori.jasper.engine.export.JRHtmlExporter; import dori.jasper.engine.*; import java.util.HashMap; public class XMLTester { public static void main(String[] args) throws dori.jasper.engine.JRException { String reportFileName = "/XMLTest.jasper"; String outFileName = "/XMLTest.html"; String xmlFileName = "/XMLTest.xml"; String recordPath = "/employees/employee/"; try { HashMap hm = new HashMap(); JasperCompileManager.compileReportToFile("/XMLTest.jrxml"); JRXMLDataSource jrxmlds = new JRXMLDataSource(xmlFileName,recordPath); JasperPrint print = JasperFillManager.fillReport( reportFileName, hm, jrxmlds); JasperExportManager.exportReportToHtmlFile(print, "D:/XMLTest.html"); JasperExportManager.exportReportToPdfFile(print, "D:/XMLTest.pdf"); System.out.println("Completed"); } catch (JRException e) { e.printStackTrace(); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } } JRXML File ========== <?xml version="1.0" encoding="UTF-8" ?> <!-- Created with iReport - A designer for JasperReports --> <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> <jasperReport name="XMLTest" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false"> <property name="ireport.scriptlethandling" value="2" /> <queryString><![CDATA[sELECT ENAME,JOB FROM EMP]]></queryString> <field name="ENAME" class="java.lang.String"> <fieldDescription><![CDATA[/employees/employee@ename]]></fieldDescription> </field> <field name="JOB" class="java.lang.String"> <fieldDescription><![CDATA[/employees/employee+JOB]]></fieldDescription> </field> <background> <band height="0" isSplitAllowed="true" > </band> </background> <title> <band height="50" isSplitAllowed="true" > </band> </title> <pageHeader> <band height="50" isSplitAllowed="true" > </band> </pageHeader> <columnHeader> <band height="30" isSplitAllowed="true" > </band> </columnHeader> <detail> <band height="25" isSplitAllowed="true" > <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Opaque" x="55" y="0" width="173" height="18" forecolor="#000000" backcolor="#FFFFFF" key="element-1" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{ENAME}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" > <reportElement mode="Opaque" x="200" y="0" width="100" height="18" forecolor="#000000" backcolor="#FFFFFF" key="element-5" stretchType="NoStretch" positionType="FixRelativeToTop" isPrintRepeatedValues="true" isRemoveLineWhenBlank="false" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false"/> <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{JOB}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band height="30" isSplitAllowed="true" > </band> </columnFooter> <pageFooter> <band height="50" isSplitAllowed="true" > </band> </pageFooter> <summary> <band height="28" isSplitAllowed="true" > </band> </summary> </jasperReport> XML file ======== <employees> <employee ename="Gopal"> <JOB>Manager</JOB> </employee> <employee ename="Krishnan"> <JOB>President</JOB> </employee> <employee ename="GopKrish"> <JOB>Clerk</JOB> </employee> </employees> By: Budi Setiawan - budse Problem while exporting report to PDF format 2004-07-15 22:06 Hello, I am new to jasper report. I tried creating a report using IReport/XML as the datasource. I used JRBeanCollectionDataSource to load the xml and i exported report to HTML and PDF format. HTML file are created successfully, but PDF file cannot be created and cause error. Please help me to figure it. File reportFile = new File(application.getRealPath("/reports/BookReport.jasper")); String namapd = reportFile.getPath().substring(0,reportFile.getPath().length()-6)+"pdf"; JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath()); DataMain dataMain = new DataMain(); dataMain.init(); JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, null, new JRBeanCollectionDataSource(dataMain.getList()) ); JRExporter exporter = new JRPdfExporter(); Map imagesMap = new HashMap(); session.setAttribute("IMAGES_MAP", imagesMap); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, namapd); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image.jsp?image="); exporter.exportReport(); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now