hi i am very new to Xml parsing
i want to change following attribute values frequently ...........
columnCount, width and height
After that i need to rewrite xml file with modified data
in following xml file by using java(sax ,Dom or jaxB parser) please any one can give some suggestion on it...............
=======================================================================================
<?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="Hello_subreport1_subreport1" language="groovy" columnCount="2" printOrder="Horizontal" pageWidth="520" pageHeight="802" columnWidth="260" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="ac19d62f-eac8-428e-8e0a-9011534189ed">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="subjectName" class="java.lang.String">
<fieldDescription><![CDATA[subjectName]]></fieldDescription>
</field>
<field name="subjectID" class="java.lang.Integer">
<fieldDescription><![CDATA[subjectID]]></fieldDescription>
</field>
<field name="maxMarks" class="java.lang.Integer">
<fieldDescription><![CDATA[maxMarks]]></fieldDescription>
</field>
<field name="redMarks" class="java.lang.Float">
<fieldDescription><![CDATA[redMarks]]></fieldDescription>
</field>
<field name="passMarks" class="java.lang.Integer">
<fieldDescription><![CDATA[passMarks]]></fieldDescription>
</field>
<field name="marks" class="java.lang.Float">
<fieldDescription><![CDATA[marks]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="52">
<textField isStretchWithOverflow="true">
<reportElement uuid="5f7665fb-9218-4434-a9e5-5eff306499b3" x="0" y="33" width="100" height="20"/>
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{marks}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="6b999cb1-600e-4634-be8f-7ac99e225f49" x="0" y="13" width="100" height="20"/>
<box>
<topPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{subjectName}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
========================================================================
If you want to modify the document them use a DOM parser. This will transform the xml file into a datastructure where you can find the attributes and change their values. Have a look at jdom or dom4j, they are really easy to use.
A sax parser is a good choice if you only want to read the document. That parser just creates events while parsing the document.
Answering to your comment: I do not get a NPE but the rootNode.getChild("detail")) return null. That is because the element is associated with a namespace. Replace the last line in your sample code with
System.out.println(rootNode.getChild("detail", rootNode.getNamespace()));
That works.
there are tons of documents on web detailing editing of an XML. Explore them and then try something out. If you are stuck then post it here.
some ref: http://www.w3schools.com/dom/default.asp
How to modify XML data in Dom parser
http://www.mkyong.com/java/how-to-modify-xml-file-in-java-dom-parser/
http://www.drdobbs.com/jvm/easy-dom-parsing-in-java/231002580
Maybe you could use avc-binding-dom, which binds DOM nodes to your custom Java interface via annotations:
import org.w3c.dom.Node;
import net.avcompris.binding.annotation.XPath;
import net.avcompris.binding.dom.impl.DefaultDomBinder;
#Namespaces("xmlns:jr=http://jasperreports.sourceforge.net/jasperreports")
#XPath("/jr:jasperReport")
interface MyJasperReport {
#XPath("#columnCount")
int getColumnCount();
void setColumnCount(int columnCount);
#XPath("#pageWidth")
int getPageWidth();
void setPageWidth(int pageWidth);
#XPath("jr:property[#name = 'ireport.zoom']/#value")
String getZoom();
void setZoom(String zoom);
}
Node node = ... // You have to load the XML file into a DOM node.
MyJasperReport jr = new DefaultDomBinder().bind(node, MyJasperReport.class);
jr.setColumnCount(4); // previously: 2
jr.setPageWidth(1024); // previously: 520
jr.setZoom("1.45"); // previously: "1.0"
... // then save the DOM node into a XML file.
Related
Currently I'm trying to use a textField with markup="html" but it's not working.
Example
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="100" y="0" width="450" height="25" isPrintWhenDetailOverflows="true" uuid="1aeaa5e9-4136-4239-a301-2733598340d9">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement verticalAlignment="Middle" markup="html">
<paragraph lineSpacing="Single" leftIndent="5" rightIndent="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{question}]]></textFieldExpression>
$F{question} contain:
"<p id="id"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mo>+</mo><mo> </mo><mi>B</mi><mo> </mo><mo> </mo><msqrt><mi>c</mi><mfenced><mrow><mi>d</mi><mfenced open="[" close="]"><mi>r</mi></mfenced></mrow></mfenced></msqrt><mo> </mo><mi>δ</mi><mo> </mo><mo>∞</mo><mi mathvariant="normal">π</mi><mo> </mo></math></p>"
Expected Result :
Result which I get :
The textField does not support MathML, it only support very basic html nor can you use the html component since the JEditorPane on which it's built neither does support MathML
You will need an external library as for example jeuclid, once that you have this library in classpath you can render the xml to a BufferedImage using Converter.render and then display it in jasper report.
This can be done without a java helper class as in this example, hence writting all the code directly in the jrxml on 1 line (using the builder pattern below), but for clarity of example I'm will use external helper class.
Example
java
public class MathML {
public static BufferedImage getImage(String xml, float size) throws IOException, SAXException, ParserConfigurationException {
// Load the string to a node
Element node = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)))
.getDocumentElement();
//Generate the layout parameter
MutableLayoutContext params = new LayoutContextImpl(
LayoutContextImpl.getDefaultLayoutContext());
params.setParameter(Parameter.MATHSIZE, size);
//Render the xml to a BufferedImage
return Converter.getInstance().render(node, params);
}
}
jrxml
<?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="Blank_A4_12" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8deaea2e-3739-4c4e-b2b5-8c58773ab1a0">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="50" splitType="Stretch">
<image>
<reportElement x="0" y="0" width="100" height="50" uuid="9ee17167-a91e-4725-b36e-a4bba5e24acb">
</reportElement>
<imageExpression><![CDATA[it.jdd.MathML.getImage("<math xmlns='http://www.w3.org/1998/Math/MathML'><mi>A</mi><mo>+</mo><mo> </mo><mi>B</mi><mo> </mo><mo> </mo><msqrt><mi>c</mi><mfenced><mrow><mi>d</mi><mfenced open='[' close=']'><mi>r</mi></mfenced></mrow></mfenced></msqrt><mo> </mo><mi>δ</mi><mo> </mo><mo>∞</mo><mi mathvariant='normal'>π</mi><mo> </mo></math>",70f)]]></imageExpression>
</image>
</band>
</title>
</jasperReport>
Output (export to pdf)
I was able to start with MultiAxis Chart with Jasper report using Link : create MultiAxis Chart with Jasper report.
I was able to creat the chart as well but not completely formatted. I was having Axis Problem. Both X-axis are coming on left side. How do I move one Axis of bar chart on right side. Following is the picture of my current problem:
Following is my jrxml content.
<?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="cutting_indicator_cutter" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="48"/>
<subDataset name="chart1">
<queryString language="SQL">
<![CDATA[select Q.proddate,NVL(Q.m2NetReel,0)
,case when Q.HMO <> 0 then
NVL((Q.m2NetReel/Q.HMO),0)
end as m2NETBYHMO,
Q.Objectif_HMOBY1000
from (
SELECT
PROD_DATE as proddate,
case when CUTTING_PRODUCTIVITY.REMAKE_CUT_SQM is null then CUTTING_PRODUCTIVITY.CUTTER_NET_SQM
else
CUTTING_PRODUCTIVITY.CUTTER_NET_SQM + CUTTING_PRODUCTIVITY.REMAKE_CUT_SQM
end as m2NetReel,
(CUTTING_PRODUCTIVITY.MACHINE_WORKING_HOURS_NORM * CUTTING_PRODUCTIVITY.USER_QUANTITY ) as HMO,
1000/(CUTTING_MACHINE.CADENCY*19.26) as Objectif_HMOBY1000
FROM CUTTING_PRODUCTIVITY CUTTING_PRODUCTIVITY
INNER JOIN CUTTING_MACHINE CUTTING_MACHINE
ON CUTTING_MACHINE_ID=CUTTING_MACHINE.CUTTING_ID where trunc(CUTTING_PRODUCTIVITY.PROD_DATE) >= '1-May-15' and trunc( CUTTING_PRODUCTIVITY.PROD_DATE ) <='31-May-15'
ORDER BY CUTTER) Q]]>
</queryString>
<field name="PRODDATE" class="java.sql.Timestamp"/>
<field name="NVL(Q.M2NETREEL,0)" class="java.math.BigDecimal"/>
<field name="M2NETBYHMO" class="java.math.BigDecimal"/>
<field name="OBJECTIF_HMOBY1000" class="java.math.BigDecimal"/>
</subDataset>
<queryString>
<![CDATA[SELECT EST_CUTTER_GLASSES_QTY,
CUTTER_NET_SQM,
REMAKE_CUT_QTY,
PROD_DATE,
REMAKE_CUT_SQM,
CUTTING_MACHINE.CADENCY,
USER_QUANTITY,
CUTTER,
MACHINE_WORKING_HOURS_NORM
FROM CUTTING_PRODUCTIVITY CUTTING_PRODUCTIVITY
INNER JOIN CUTTING_MACHINE CUTTING_MACHINE
ON CUTTING_MACHINE_ID=CUTTING_MACHINE.CUTTING_ID
where trunc(CUTTING_PRODUCTIVITY.PROD_DATE) >= '1-May-15' and trunc( CUTTING_PRODUCTIVITY.PROD_DATE ) <='31-May-15'
ORDER BY CUTTER]]>
</queryString>
<field name="EST_CUTTER_GLASSES_QTY" class="java.math.BigDecimal"/>
<field name="CUTTER_NET_SQM" class="java.math.BigDecimal"/>
<field name="REMAKE_CUT_QTY" class="java.math.BigDecimal"/>
<field name="PROD_DATE" class="java.sql.Timestamp"/>
<field name="REMAKE_CUT_SQM" class="java.math.BigDecimal"/>
<field name="CADENCY" class="java.math.BigDecimal"/>
<field name="USER_QUANTITY" class="java.math.BigDecimal"/>
<field name="CUTTER" class="java.lang.String"/>
<field name="MACHINE_WORKING_HOURS_NORM" class="java.math.BigDecimal"/>
<group name="CUTTER">
<groupExpression><![CDATA[$F{CUTTER}]]></groupExpression>
<groupHeader>
<band height="325">
<frame>
<reportElement x="0" y="0" width="555" height="325" printWhenGroupChanges="CUTTER"/>
<multiAxisChart>
<chart renderType="svg" theme="generic">
<reportElement x="24" y="0" width="486" height="325">
<property name="net.sf.jasperreports.chart.range.axis.tick.interval" value="2"/>
</reportElement>
<chartTitle/>
<chartSubtitle/>
<chartLegend position="Bottom"/>
</chart>
<multiAxisPlot>
<plot/>
<axis>
<lineChart>
<chart renderType="svg">
<reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF"/>
<chartTitle color="#000000"/>
<chartSubtitle color="#000000"/>
<chartLegend textColor="#000000" backgroundColor="#FFFFFF" position="Bottom"/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="chart1">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA["WEIGHTAVG"]]></seriesExpression>
<categoryExpression><![CDATA[$F{PRODDATE}]]></categoryExpression>
<valueExpression><![CDATA[$F{NVL(Q.M2NETREEL,0)}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["OBJECTIF"]]></seriesExpression>
<categoryExpression><![CDATA[$F{PRODDATE}]]></categoryExpression>
<valueExpression><![CDATA[$F{OBJECTIF_HMOBY1000}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot isShowLines="true" isShowShapes="true">
<plot labelRotation="-45.0"/>
</linePlot>
</lineChart>
</axis>
<axis>
<barChart>
<chart renderType="svg">
<reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF"/>
<chartTitle color="#000000"/>
<chartSubtitle color="#000000"/>
<chartLegend textColor="#000000" backgroundColor="#FFFFFF" position="Bottom"/>
</chart>
<categoryDataset>
<dataset>
<datasetRun subDataset="chart1">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
<categorySeries>
<seriesExpression><![CDATA["M2NetHMO"]]></seriesExpression>
<categoryExpression><![CDATA[$F{PRODDATE}]]></categoryExpression>
<valueExpression><![CDATA[$F{M2NETBYHMO}]]></valueExpression>
</categorySeries>
</categoryDataset>
<barPlot>
<plot/>
<itemLabel/>
</barPlot>
</barChart>
</axis>
</multiAxisPlot>
</multiAxisChart>
</frame>
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="50"/>
</title>
</jasperReport>
How do I move my bar chart axis to right?
To move an axis to the right side of the chart in jasper reports, you'll need to create a Customizer for your chart. Once you do that, the following commands in your customizer will move your axis to the right side of the chart:
// get plot from chart object
CategoryPlot plot = (CategoryPlot) chart.getPlot();
// move axis to right side of chart
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
I want to print the content of an ArrayList using JasperReports in Java
Actually I am know little about Jasper Reporting
I use iReport to create Japser Reports and using Java command I will print it.
Now I want to print the student results using JasperReports.
This is my sample results table.
Reg.No SubjectCode Level Semester Grade Marks
132108 CMIS 1113 1 1 A 77
132107 CMIS 1213 1 2 C 57
122101 IMGT 2112 2 1 A 87
122110 IMGT 2213 2 2 A 83
112123 STAT 3113 3 1 C 55
112135 MATH 3213 3 2 B 67
132145 CMIS 1113 1 1 D 17
122118 ELTN 2213 1 2 A 90
112100 CMIS 3213 3 2 A 89
112117 SATA 3113 1 1 A 87
122104 CMIS 2213 2 2 C 54
132104 CMIS 1213 1 2 A 84
So according to my above table I need to print "Results of student in particular level in particular semester".
In my interface I have facility to select the Level and the Semester.
Then the relevant query with generate automatically and results will obtain from the database and using Results object(I create class called 'Results' to store the results of a particular student) I add the results data to a ArrayList.
Now my ArrayList have the Results objects which carries the results of each students in particular level and particular semester.Now I want to print this ArrayList using Jasper report.So expected Jasper Report is like this.For Level 1 and Semester 1,
Reg.No CMIS1113
132108 A
132145 D
For Level 2 and Semester 2,
Reg.No IMGT2213 CMIS2213
122110 A -
122104 - C
Now I have several problems.
1) Normally what I did previously is when I create Jasper Template using iReport I gave the relevant query before creating it.But here query will be changed according to selected Level and Semester.So the result will be changed according to the query.And column headers also changed because subjects are changing.(Number of subject are not similar in each semester and each level)So my question is how can I create a common Jasper Templates to Handle each situation?(if possible)
2) How I print the ArrayList using Java code.I do not know the java code to print the content of ArrayList using Jasper Report.
I know very few things about Jasper Reports.So if you can please help me.Thank You.
you can pass the ArrayList to report as a parameter.
Then in Report create a Subdataset with the same parameter name and type (ArrayList).
Then Create a table component. use the ConnectionExpression:
new net.sf.jasperreports.engine.JREmptyDataSource($P{IN_ARRAY_LIST}.size())
Then map report parameter to table parameter.
Then in TextFields in the table component you can use the expression like that:
$P{IN_ARRAY_LIST}.get($V{REPORT_COUNT})
Make sure that EvaluationTime property of your TextFields is set to now.
UPD:
Short demo report which shows how ArrayList source works:
<?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="ArrayList" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c67d12d3-80cd-46fb-8a79-5c4b0b7c76f9">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="TableDataset" uuid="628eb9fb-e4f0-4f6c-b5b3-277a14fda6e2">
<parameter name="IN_ARRAY_LIST" class="java.util.ArrayList" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.util.ArrayList()]]></defaultValueExpression>
</parameter>
<variable name="ROW_INDEX" class="java.lang.Integer" resetType="None">
<variableExpression><![CDATA[$V{REPORT_COUNT} - 1]]></variableExpression>
</variable>
</subDataset>
<!-- WHEN YOU CALL YOUR REPORT FROM JAVA, YOU SHOULD PUT YOUR ArrayList into IN_ARRAY_LIST PARAM-->
<parameter name="IN_ARRAY_LIST" class="java.util.ArrayList" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.util.ArrayList()]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="555" height="20" uuid="d4548efc-5711-42b3-b08a-cb138c5d55cf">
<!-- THIS IS FOR DEMO ONLY - I PUT 2 ROWS INTO ARRAY LIST USING PrintWhenExpression -->
<printWhenExpression><![CDATA[$P{IN_ARRAY_LIST}.add("ROW_1") && $P{IN_ARRAY_LIST}.add("ROW_2")]]></printWhenExpression>
</reportElement>
<text><![CDATA[Report Title]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="20" splitType="Stretch"/>
</pageHeader>
<pageFooter>
<band height="20" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="50" splitType="Stretch">
<componentElement>
<reportElement key="table" x="0" y="0" width="555" height="50" uuid="042cdee2-a56a-49af-8a1b-740825446ed5"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="TableDataset" uuid="6f17f8a5-0bcc-4e2a-a900-cdb1e1261d24">
<datasetParameter name="IN_ARRAY_LIST">
<datasetParameterExpression><![CDATA[$P{IN_ARRAY_LIST}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($P{IN_ARRAY_LIST}.size())]]></dataSourceExpression>
</datasetRun>
<jr:column width="555" uuid="236aa389-6073-48fa-9b0f-02dcec80551e">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="555" height="30" uuid="18d3f3cc-13fa-4203-b239-45739b1839dc"/>
<text><![CDATA[ArrayList Field Value]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="555" height="20" uuid="a5bd535e-091b-4eef-a0af-e70fc7d2cce2"/>
<textFieldExpression><![CDATA[$P{IN_ARRAY_LIST}.get($V{ROW_INDEX})]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>
I hope this is clear now.
I have a Java class with two attribute id (integer) and name (string). I have created a list of objects and I want to use the JasperReports to make a pdf file.
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(conceptsList,true);
Map jasperParameters = new HashMap();
jasperParameters.put("Concepts", ds);
String input = "C:/report.jasper";
JasperPrint jp = JasperFillManager.fillReport(input, jasperParameters, new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jp, "C:/report.pdf");
In iReport Designer I have one parameter (Concepts) and set net.sf.jasperreports.engine.data.JRBeanCollectionDataSource as a parameter class. I also define two fields id and name and put them in the details band. but my pdf file does not show anything. I think somewhere I have to define datasource for id and name but I cannot find anything. It would be great if anyone can help me.
<?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="report22" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="313d6b25-bcea-43a0-80db-2c7733499ca2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="Concepts" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<field name="name" class="java.lang.String"/>
<title>
<band height="50" splitType="Stretch"/>
</title>
<detail>
<band height="200" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="b6c2dc20-ebaa-4dfe-8d42-b8318bf05d33"/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20" uuid="fbc83087-e178-4210-a9f0-a8e1d86a5f71"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
You can send the object data as a datasource to JRXML. Additionally, if the List should also be sent as a datasource to JRXML.
First design the iReport to accept Object as datasource:
1) Add the project "src" in class-path in iReport.
2) Specify the object package.className in JRXML report datasource.
3) Map the TextFields with the Object parameters.
Now in source code, use "JRBeanCollectionDataSource" Class for sending the List of Object in "JasperFillManager.fillReport()", for Connection.
Hope this helps.
A simple report with only a png in it.
Png's dpi is 96, which looks pretty sharp. However, every time i export the report, be it to .docx or to pdf, only an awfully blurry image appears.
i've tried setting
net.sf.jasperreports.image.dpi
to 300, and to 96
both in ireports and directly on the report's jrxml as a property.
Nothing works.
exception
I've lost many days googling this matter but still no answers.
Update 1
I've been able to trace the cause of this strange behavior to itext. It seems that it has to do something with it.
Update 2
Here's the jrxml code
<?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="carta_policia" pageWidth="612" pageHeight="792" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fbda9a68-7549-438c-a8ad-b3aedaf0b2d4">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.background.image" value="C:\Users\thou\workspace\cujillo\WebContent\resources\reports\fondo.png"/>
<property name="ireport.background.image.properties" value="false,true,0.25,0,0,0,0,0,0"/>
<property name="net.sf.jasperreports.image.dpi" value="96"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:/Users/thou/workspace/cujillo/WebContent/resources/reports/"]]></defaultValueExpression>
</parameter>
<parameter name="R_RADICADO" class="java.lang.String"/>
<parameter name="SUBREPORT_DATA_SOURCE" class="net.sf.jasperreports.engine.JRDataSource"/>
<parameter name="R_ASUNTO" class="java.lang.String"/>
<parameter name="R_LOCALIDAD" class="java.lang.String"/>
<parameter name="R_IMAGE_RENDERER" class="net.sf.jasperreports.engine.JRRenderable" isForPrompting="false"/>
<parameter name="R_PRINT_BACKGROUND" class="java.lang.String"/>
<background>
<band height="752"/>
</background>
<title>
<band height="371" splitType="Stretch">
<image scaleImage="RealSize">
<reportElement uuid="dbadb500-4011-415b-bd98-4236532783c4" x="234" y="147" width="75" height="63"/>
<imageExpression><![CDATA["C:\\Users\\thou\\workspace\\cujillo\\WebContent\\resources\\reports\\alcaldia mayor.png"]]></imageExpression>
</image>
<image scaleImage="Clip">
<reportElement uuid="ecf7dbe3-4369-41a8-ba49-db98ba5ef478" x="309" y="151" width="75" height="63"/>
<imageExpression><![CDATA["C:\\Users\\thou\\workspace\\cujillo\\WebContent\\resources\\reports\\alcaldia mayor.jpg"]]></imageExpression>
</image>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="104" splitType="Stretch"/>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="11" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="209" splitType="Stretch"/>
</summary>
</jasperReport>
Although we've raised the DPI setting in our presentations, I've implemented a custom exporter, which exports charts as powerpoint shapes and not as raster images.
At least for .docx it's feasible to implement something similar.
Before I've started the shape export classes, I've tried to use EMF (1,2) as an image format, but this is quite limited, e.g. it doesn't embed fonts.
I haven't searched further in the direction, but maybe you can transform an intermediate SVG image to something (raster/vector) which can be embedded into .docx/.pdf.
Have you checked the images inside .docx-Zip-file? ... are the plain images also blurry or just when they are displayed by Word/LibreOffice. And of course the images should change after you changed the DPI setting - if not, try to put a jasperreports.properties in the classpath